Skip to content

Commit 9bc860f

Browse files
authored
Forms: fix single input general error (#45796)
* changelog * use field error for form error when single input form
1 parent fdd19e9 commit 9bc860f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Forms: single input forms don't show general errors, move general form error into field error when necessary

projects/packages/forms/src/contact-form/class-contact-form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ public static function parse( $attributes, $content, $context = array() ) {
806806
'submissionSuccess' => $submission_success,
807807
'submissionError' => null,
808808
'elementId' => $element_id,
809+
'isSingleInputForm' => $is_single_input_form,
809810
);
810811

811812
if ( $is_multistep ) {

projects/packages/forms/src/modules/form/view.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ const { state, actions } = store( NAMESPACE, {
183183
return false;
184184
}
185185

186+
// For single input forms, show submission errors in the field error div
187+
if ( context.isSingleInputForm && context.submissionError ) {
188+
return true;
189+
}
190+
186191
return ( context.showErrors || field.showFieldError ) && field.error && field.error !== 'yes';
187192
},
188193

@@ -233,6 +238,11 @@ const { state, actions } = store( NAMESPACE, {
233238
const fieldId = context.fieldId;
234239
const field = context.fields[ fieldId ] || {};
235240

241+
// For single input forms, show submission errors in the field error div
242+
if ( context.isSingleInputForm && context.submissionError ) {
243+
return context.submissionError;
244+
}
245+
236246
if ( ! ( context.showErrors || field.showFieldError ) || ! field.error ) {
237247
return '';
238248
}

0 commit comments

Comments
 (0)