Simplify autofocus code
This commit is contained in:
parent
97e95e3e99
commit
d4a7490ff0
File diff suppressed because one or more lines are too long
|
@ -1875,12 +1875,6 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
|
|||
$required = '';
|
||||
}
|
||||
|
||||
$args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : '';
|
||||
|
||||
$args['autocomplete'] = ( $args['autocomplete'] ) ? 'autocomplete="' . esc_attr( $args['autocomplete'] ) . '"' : '';
|
||||
|
||||
$args['autofocus'] = ( true === $args['autofocus'] ) ? apply_filters( 'woocommerce_form_field_autofocus', 'autofocus' ) : '' ;
|
||||
|
||||
if ( is_string( $args['label_class'] ) ) {
|
||||
$args['label_class'] = array( $args['label_class'] );
|
||||
}
|
||||
|
@ -1898,6 +1892,18 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $args['maxlength'] ) {
|
||||
$custom_attributes['maxlength'] = absint( $args['maxlength'] );
|
||||
}
|
||||
|
||||
if ( true === $args['autocomplete'] ) {
|
||||
$custom_attributes['autocomplete'] = 'true';
|
||||
}
|
||||
|
||||
if ( true === $args['autofocus'] ) {
|
||||
$custom_attributes['autofocus'] = 'autofocus';
|
||||
}
|
||||
|
||||
if ( ! empty( $args['validate'] ) ) {
|
||||
foreach ( $args['validate'] as $validate ) {
|
||||
$args['class'][] = 'validate-' . $validate;
|
||||
|
@ -1967,7 +1973,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
|
|||
break;
|
||||
case 'textarea' :
|
||||
|
||||
$field .= '<textarea name="' . esc_attr( $key ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" ' . $args['maxlength'] . ' ' . $args['autocomplete'] . ' ' . ( empty( $args['custom_attributes']['rows'] ) ? ' rows="2"' : '' ) . ( empty( $args['custom_attributes']['cols'] ) ? ' cols="5"' : '' ) . implode( ' ', $custom_attributes ) . esc_attr( $args['autofocus'] ) . '>' . esc_textarea( $value ) . '</textarea>';
|
||||
$field .= '<textarea name="' . esc_attr( $key ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" ' . $args['maxlength'] . ' ' . $args['autocomplete'] . ' ' . ( empty( $args['custom_attributes']['rows'] ) ? ' rows="2"' : '' ) . ( empty( $args['custom_attributes']['cols'] ) ? ' cols="5"' : '' ) . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $value ) . '</textarea>';
|
||||
|
||||
break;
|
||||
case 'checkbox' :
|
||||
|
@ -1983,7 +1989,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
|
|||
case 'tel' :
|
||||
case 'number' :
|
||||
|
||||
$field .= '<input type="' . esc_attr( $args['type'] ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" ' . $args['maxlength'] . ' ' . $args['autocomplete'] . ' value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . esc_attr( $args['autofocus'] ) . ' />';
|
||||
$field .= '<input type="' . esc_attr( $args['type'] ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" ' . $args['maxlength'] . ' ' . $args['autocomplete'] . ' value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
|
||||
|
||||
break;
|
||||
case 'select' :
|
||||
|
|
Loading…
Reference in New Issue