@@ -2843,13 +2843,16 @@ ComponentRegistry.register('form',
28432843 * carries `data-field` (FormItem), so this reaches custom widgets that RHF's
28442844 * own focus cannot (#2793).
28452845 */
2846- const revealField = ( name : string ) => {
2846+ const fieldWrapper = ( name : string ) : HTMLElement | null => {
28472847 const root : ParentNode = formRef . current ?? document ;
28482848 const escaped =
28492849 typeof CSS !== 'undefined' && typeof CSS . escape === 'function'
28502850 ? CSS . escape ( name )
28512851 : name . replace ( / [ " \\ ] / g, '\\$&' ) ;
2852- const target = root . querySelector < HTMLElement > ( `[data-field="${ escaped } "]` ) ;
2852+ return root . querySelector < HTMLElement > ( `[data-field="${ escaped } "]` ) ;
2853+ } ;
2854+ const revealField = ( name : string ) => {
2855+ const target = fieldWrapper ( name ) ;
28532856 if ( target ) {
28542857 target . scrollIntoView ?.( { behavior : 'smooth' , block : 'center' } ) ;
28552858 const focusable = target . querySelector < HTMLElement > (
@@ -2860,54 +2863,64 @@ ComponentRegistry.register('form',
28602863 } ;
28612864
28622865 /**
2863- * Tell the user WHICH fields are wrong, wherever the verdict came from.
2866+ * Point the user at the fields that are wrong, wherever the verdict came
2867+ * from: reveal and focus the FIRST of them (in declared/visual order, not
2868+ * the caller's key order), activating its tab first when it sits on a
2869+ * background one.
2870+ *
2871+ * No toast. Every field this reaches carries its own message under the
2872+ * input, so a toast naming the same fields only repeated them — truncated
2873+ * after three names, and drawn over the record dialog's title row, which it
2874+ * hid. Moving focus to the first offender is what makes a refused submit
2875+ * visible on a long form; the inline messages say the rest.
28642876 *
2865- * Toast naming the offending fields, then reveal the FIRST of them (in
2866- * declared/visual order, not the caller's key order) — activating its tab
2867- * first when it sits on a background one.
2877+ * Returns the rejected names that have NO drawn input — a field on a
2878+ * predicate-hidden tab (#6237) or section, or hidden by its own rule. Only
2879+ * the SERVER can reject those (their client rules are skipped with them),
2880+ * and nothing inline can carry the message, so the caller must say it at
2881+ * form level instead.
28682882 *
28692883 * Shared by the client-side invalid handler and the SERVER-rejection path:
28702884 * the two failures are the same event as far as the person filling the form
28712885 * is concerned; only the referee differs.
28722886 */
2873- const announceFieldErrors = ( names : string [ ] ) => {
2874- if ( names . length === 0 ) return ;
2887+ const announceFieldErrors = ( names : string [ ] ) : string [ ] => {
2888+ if ( names . length === 0 ) return [ ] ;
28752889 setRejectedFieldNames ( names ) ;
2876- const labels = names . map ( ( n ) => fieldLabelByName [ n ] || n ) ;
2877- const MAX = 3 ;
2878- const fieldsText =
2879- labels . slice ( 0 , MAX ) . join ( t ( 'validation.formInvalidJoiner' ) ) +
2880- ( labels . length > MAX ? '…' : '' ) ;
2881- toast . error ( t ( 'validation.formInvalid' , { fields : fieldsText } ) , { id : outcomeToastId } ) ;
2882-
28832890 const errored = new Set ( names ) ;
2884- const firstName =
2885- ( fields as FormFieldConfig [ ] )
2891+ const ordered = [
2892+ ... ( fields as FormFieldConfig [ ] )
28862893 . map ( ( f ) => f ?. name )
2887- . find ( ( n ) : n is string => Boolean ( n ) && errored . has ( n as string ) ) ?? names [ 0 ] ;
2894+ . filter ( ( n ) : n is string => Boolean ( n ) && errored . has ( n as string ) ) ,
2895+ ...names . filter ( ( n ) => ! ( fields as FormFieldConfig [ ] ) . some ( ( f ) => f ?. name === n ) ) ,
2896+ ] ;
2897+ // A field is drawn when its wrapper is in the DOM. A background tab's
2898+ // panel stays mounted (CSS-hidden), so its fields count as drawn and are
2899+ // reached below by activating the tab; a predicate-hidden tab's panel is
2900+ // not rendered at all, so its fields do not.
2901+ const undrawn = ordered . filter ( ( n ) => ! fieldWrapper ( n ) ) ;
2902+ const firstName = ordered . find ( ( n ) => ! undrawn . includes ( n ) ) ;
2903+ if ( ! firstName ) return undrawn ;
28882904
28892905 // In a tabbed layout the offending field may sit on a tab the user is not
2890- // looking at — naming it is useless if they can't see it. Activate its tab
2891- // first, then reveal it once that panel has actually been painted (it is
2892- // display:none until then, so scroll/focus would no-op).
2893- //
2894- // Unless the tab is predicate-HIDDEN (#6237): only the SERVER can reject
2895- // a field there (its client rules are skipped with it), and there is no
2896- // panel to activate or control to reveal — the toast above already names
2897- // the field. Recording the activation as a pick anyway would yank the
2898- // view to that tab whenever its predicate later re-admits it.
2906+ // looking at — the message under it is useless if they can't see it.
2907+ // Activate its tab first, then reveal it once that panel has actually
2908+ // been painted (it is display:none until then, so scroll/focus would
2909+ // no-op). A predicate-HIDDEN tab is never activated: recording that as a
2910+ // pick would yank the view to it whenever its predicate later re-admits
2911+ // it, and a drawn field it also claims is rendered in a visible panel.
28992912 const tabKey = tabKeyByFieldName . get ( firstName ) ;
2900- if ( tabKey && hiddenFieldTabKeys . has ( tabKey ) ) return ;
2901- if ( tabKey && tabKey !== activeFieldTab ) {
2913+ if ( tabKey && ! hiddenFieldTabKeys . has ( tabKey ) && tabKey !== activeFieldTab ) {
29022914 setPickedFieldTab ( tabKey ) ;
29032915 if ( typeof requestAnimationFrame === 'function' ) {
29042916 requestAnimationFrame ( ( ) => revealField ( firstName ) ) ;
29052917 } else {
29062918 setTimeout ( ( ) => revealField ( firstName ) , 0 ) ;
29072919 }
2908- return ;
2920+ return undrawn ;
29092921 }
29102922 revealField ( firstName ) ;
2923+ return undrawn ;
29112924 } ;
29122925
29132926 // Handle form submission — react-hook-form's validation, then the write.
@@ -3008,11 +3021,14 @@ ComponentRegistry.register('form',
30083021 // this form does not render, fall through: the top-level message
30093022 // concatenates every field's reason, so the part the user cannot see
30103023 // inline is still said out loud instead of silently dropped.
3024+ // The same holds for a rendered-schema field with no DRAWN input
3025+ // (a predicate-hidden tab or section): `announceFieldErrors` names
3026+ // those, and any one of them sends the failure down the same path.
30113027 if ( known . length > 0 && known . length === fieldErrors . length ) {
3012- announceFieldErrors ( known . map ( ( fe ) => fe . field ) ) ;
3028+ const undrawn = announceFieldErrors ( known . map ( ( fe ) => fe . field ) ) ;
30133029 // A fully-attributed rejection is not a form-level failure — the
30143030 // banner would just repeat what is now written under each input.
3015- return ;
3031+ if ( undrawn . length === 0 ) return ;
30163032 }
30173033 }
30183034 // A rejected write used to be rendered verbatim, which put raw server
@@ -3055,8 +3071,10 @@ ComponentRegistry.register('form',
30553071 // Client-side (react-hook-form) validation blocked the submit. The
30563072 // per-field errors render inline, but in long forms the offending field
30573073 // is often scrolled out of view — the user clicks 创建 and sees nothing
3058- // happen. Surface a toast naming the fields so the feedback is visible
3059- // regardless of scroll position (mirrors the server-error toast above).
3074+ // happen. Move focus to the first offender so the feedback is visible
3075+ // regardless of scroll position. Every name here has a drawn input:
3076+ // react-hook-form validates only mounted controls, and an undrawn field
3077+ // is unmounted, so the returned list is always empty on this path.
30603078 announceFieldErrors ( Object . keys ( validationErrors || { } ) ) ;
30613079 } ) ;
30623080
@@ -3458,8 +3476,9 @@ ComponentRegistry.register('form',
34583476 // parents still read two ways (objectui#4026). The separator is a
34593477 // property of the locale, so all of them now read
34603478 // `validation.formInvalidJoiner`: the key objectstack#5407 added for the
3461- // invalid-submit toast a few hundred lines up, which is the same class
3462- // of truncated-name list, rather than a second gate-only twin that would
3479+ // invalid-submit field list (that toast is gone; the `visibleWhen`
3480+ // refusal a few hundred lines up still joins with it), which is the same
3481+ // class of name list, rather than a second gate-only twin that would
34633482 // reintroduce the divergence.
34643483 const gatedHint = optionGroupGated
34653484 ? t ( 'fields.options.selectFirst' , {
0 commit comments