| @@ -291,9 +291,17 @@ | ||
| 291 | 291 | private function replace_error_shortcode() { |
| 292 | 292 | $this->maybe_add_error_id(); |
| 293 | 293 | $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false; |
| 294 | 294 | |
| 295 | - if ( $error && ! str_contains( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) { | |
| 295 | + if ( ! $error ) { | |
| 296 | + FrmShortcodeHelper::remove_inline_conditions( false, 'error', $error, $this->html ); | |
| 297 | + return; | |
| 298 | + } | |
| 299 | + | |
| 300 | + $include_alert_role_on_field_errors = FrmAppHelper::should_include_alert_role_on_field_errors(); | |
| 301 | + $has_alert_role = str_contains( $this->html, 'role="alert"' ); | |
| 302 | + | |
| 303 | + if ( ! $has_alert_role && $include_alert_role_on_field_errors ) { | |
| 296 | 304 | $error_body = self::get_error_body( $this->html ); |
| 297 | 305 | |
| 298 | 306 | if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) { |
| 299 | 307 | $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 ); |
| @@ -298,11 +306,13 @@ | ||
| 298 | 306 | if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) { |
| 299 | 307 | $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 ); |
| 300 | 308 | $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html ); |
| 301 | 309 | } |
| 310 | + } elseif ( ! $include_alert_role_on_field_errors && $has_alert_role ) { | |
| 311 | + $this->html = str_replace( 'role="alert"', '', $this->html ); | |
| 302 | 312 | } |
| 303 | 313 | |
| 304 | - FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html ); | |
| 314 | + FrmShortcodeHelper::remove_inline_conditions( true, 'error', $error, $this->html ); | |
| 305 | 315 | } |
| 306 | 316 | |
| 307 | 317 | /** |
| 308 | 318 | * Pull the HTML between [if error] and [/if error] shortcodes. |