| @@ -136,8 +136,10 @@ | ||
| 136 | 136 | $this->replace_entry_key(); |
| 137 | 137 | $this->replace_form_shortcodes(); |
| 138 | 138 | $this->process_wp_shortcodes(); |
| 139 | 139 | $this->maybe_replace_description_shortcode( true ); |
| 140 | + | |
| 141 | + $this->add_multiple_input_attributes(); | |
| 140 | 142 | } |
| 141 | 143 | |
| 142 | 144 | /** |
| 143 | 145 | * @since 3.0 |
| @@ -482,6 +484,44 @@ | ||
| 482 | 484 | private function process_wp_shortcodes() { |
| 483 | 485 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 484 | 486 | $this->html = do_shortcode( $this->html ); |
| 485 | 487 | } |
| 488 | + } | |
| 489 | + | |
| 490 | + /** | |
| 491 | + * Adds multiple input attributes. | |
| 492 | + * | |
| 493 | + * @since 6.4.1 | |
| 494 | + * @return void | |
| 495 | + */ | |
| 496 | + private function add_multiple_input_attributes() { | |
| 497 | + $field_type = $this->field_obj->get_field_column( 'type' ); | |
| 498 | + | |
| 499 | + // Check if the field type is one of the following. | |
| 500 | + if ( ! in_array( $field_type, array( 'radio', 'checkbox', 'data', 'product', 'scale' ), true ) ) { | |
| 501 | + return; | |
| 502 | + } | |
| 503 | + | |
| 504 | + $field = (array) $this->field_obj->get_field(); | |
| 505 | + $attributes = array(); | |
| 506 | + | |
| 507 | + // Check if the field type is 'data' or 'product'. | |
| 508 | + if ( in_array( $field_type, array( 'data', 'product' ), true ) ) { | |
| 509 | + $data_type = FrmField::get_option( $field, 'data_type' ); | |
| 510 | + $is_radio = 'radio' === $data_type; | |
| 511 | + } else { | |
| 512 | + $is_radio = 'radio' === $field_type || 'scale' === $field_type; | |
| 513 | + } | |
| 514 | + | |
| 515 | + // Add 'role' attribute to the field. | |
| 516 | + $attributes['role'] = $is_radio ? 'radiogroup' : 'group'; | |
| 517 | + | |
| 518 | + // Add 'aria-required' attribute to the field if required. | |
| 519 | + if ( $is_radio && '1' === $field['required'] ) { | |
| 520 | + $attributes['aria-required'] = 'true'; | |
| 521 | + } | |
| 522 | + | |
| 523 | + // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string. | |
| 524 | + $html_attributes = FrmAppHelper::array_to_html_params( $attributes ); | |
| 525 | + $this->html = str_replace( ' role="group"', $html_attributes, $this->html ); | |
| 486 | 526 | } |
| 487 | 527 | } |