Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c156eef
Set aria-invalid to true only on name part input with error
AbdiTolesa Oct 8, 2024
dbdc6b1
Move check into a separate function
AbdiTolesa Oct 9, 2024
601a31c
Avoid potential bug
AbdiTolesa Oct 9, 2024
9629b3c
Improve condition check
AbdiTolesa Oct 9, 2024
466860a
Add missing JSDoc
AbdiTolesa Oct 9, 2024
d34a3ee
Cut down repeated code
AbdiTolesa Oct 9, 2024
62c9d5c
Cover middle name with the fix too
AbdiTolesa Oct 9, 2024
4496a70
Fix workflow errors
AbdiTolesa Oct 9, 2024
1945a36
Fix workflow errors
AbdiTolesa Oct 9, 2024
eb3aad5
Fix workflow errors
AbdiTolesa Oct 9, 2024
1c461e2
Avoid red border on textarea:focus
AbdiTolesa Oct 22, 2024
432494c
Improve code readability a bit
AbdiTolesa Oct 23, 2024
07bbf5e
Remove check for field type
AbdiTolesa Nov 6, 2024
63a35b7
Add inline comment to explain update
AbdiTolesa Nov 6, 2024
38756ec
Refactor solution to follow an object oriented approach
AbdiTolesa Nov 6, 2024
ff2ecd2
Remove new css selector and update existing one intended for the same…
AbdiTolesa Nov 11, 2024
5972382
Move function to parent class
AbdiTolesa Nov 19, 2024
aa29c1c
Call getter function to get subfields for the current combo field
AbdiTolesa Nov 19, 2024
16874ee
Make fix more generic
AbdiTolesa Nov 20, 2024
156dc65
Merge branch 'master' into issue-5409-fix_name_field_validation_issue
Crabcyborg Nov 20, 2024
51da5b1
Exit look early if already set focus on a combo subfield
AbdiTolesa Nov 21, 2024
b8bca3c
Merge branch 'issue-5409-fix_name_field_validation_issue' of https://…
AbdiTolesa Nov 21, 2024
ec33c73
Fix JSDoc error
AbdiTolesa Nov 21, 2024
da9377d
Fix JSDoc error
AbdiTolesa Nov 21, 2024
585b814
Add missing condition check for target element's existence first
AbdiTolesa Nov 22, 2024
6b01a94
Merge branch 'master' into issue-5409-fix_name_field_validation_issue
Crabcyborg Nov 26, 2024
3616e9b
Merge branch 'master' into issue-5409-fix_name_field_validation_issue
Crabcyborg Nov 26, 2024
ab8c5cb
Use focusInput to improve support with fade in with conditional logic…
Crabcyborg Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion classes/controllers/FrmFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,16 @@ private static function add_shortcodes_to_html( $field, array &$add_html ) {
}

foreach ( $field['shortcodes'] as $k => $v ) {
if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
$subfield_name = $field['subfield_name'];
if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
Comment thread
Crabcyborg marked this conversation as resolved.
continue;
}
// Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
$k = 'aria-invalid';
$v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
}
if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
continue;
}
Expand All @@ -923,7 +933,7 @@ private static function add_shortcodes_to_html( $field, array &$add_html ) {
}

unset( $k, $v );
}
}//end foreach
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmFieldFormHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private function prepare_input_shortcode_atts( $shortcode_atts ) {
unset( $shortcode_atts['class'] );
}

$shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false';
$this->field_obj->set_aria_invalid_error( $shortcode_atts, $this->pass_args );

$this->field_obj->set_field_column( 'shortcodes', $shortcode_atts );

Expand Down
19 changes: 19 additions & 0 deletions classes/models/fields/FrmFieldCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ protected function register_sub_fields( array $sub_fields ) {
}//end foreach
}

/**
* Set the aria-invalid attribute for subfields.
*
* @since x.x
*
* @param array $shortcode_atts
* @param array $args
*
* @return void
*/
public function set_aria_invalid_error( &$shortcode_atts, $args ) {
foreach ( $this->get_sub_fields() as $sub_field ) {
$shortcode_atts[ 'aria-invalid-' . $sub_field['name'] ] = isset( $args['errors'][ 'field' . $this->field_id . '-' . $sub_field['name'] ] ) ? 'true' : 'false';
}
}

/**
* Gets default sub field.
*
Expand Down Expand Up @@ -381,6 +397,9 @@ protected function print_input_atts( $args ) {
// Fake it to avoid printing frm-val attribute.
$field['default_value'] = '';

if ( ! empty( $sub_field['name'] ) ) {
$field['subfield_name'] = $sub_field['name'];
}
do_action( 'frm_field_input_html', $field );

// Print custom attributes.
Expand Down
14 changes: 14 additions & 0 deletions classes/models/fields/FrmFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,20 @@ protected function get_input_class() {
return '';
}

/**
* Set the aria-invalid attribute for field.
*
* @since x.x
*
* @param array $shortcode_atts
* @param array $args
*
* @return void
*/
public function set_aria_invalid_error( &$shortcode_atts, $args ) {
$shortcode_atts['aria-invalid'] = isset( $args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false';
}

/**
* @param array $args
* @param array $shortcode_atts
Expand Down
2 changes: 1 addition & 1 deletion css/_single_theme.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

.<?php echo esc_html( $style_class ); ?> .form-field input:not([type=file]):not([type=range]):not([readonly]):focus,
.<?php echo esc_html( $style_class ); ?> select:focus,
.<?php echo esc_html( $style_class ); ?> textarea:focus,
.<?php echo esc_html( $style_class ); ?> .form-field textarea:focus,
.<?php echo esc_html( $style_class ); ?> .frm_focus_field input[type=text],
.<?php echo esc_html( $style_class ); ?> .frm_focus_field input[type=password],
.<?php echo esc_html( $style_class ); ?> .frm_focus_field input[type=email],
Expand Down
27 changes: 27 additions & 0 deletions js/formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,29 @@ function frmFrontFormJS() {
});
}

/**
* Sets focus on a the first subfield of a combo field that has an error.
*
* @since x.x
*
* @param {HTMLElement} element
* @return {boolean} True if the focus was set on a combo field.
*/
function maybeFocusOnComboSubField( element ) {
if ( 'FIELDSET' !== element.nodeName ) {
return false;
}
if ( ! element.querySelector( '.frm_combo_inputs_container' ) ) {
return false;
}
const comboSubfield = element.querySelector( '[aria-invalid="true"]' );
if ( comboSubfield ) {
focusInput( comboSubfield );
return true;
}
return false;
}

function checkForErrorsAndMaybeSetFocus() {
let errors, element, timeoutCallback;

Expand All @@ -1339,6 +1362,10 @@ function frmFrontFormJS() {
break;
}

if ( maybeFocusOnComboSubField( element ) ) {
break;
}

if ( 'undefined' !== typeof element.classList ) {
if ( element.classList.contains( 'html-active' ) ) {
timeoutCallback = function() {
Expand Down