-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add global setting for form submission message #1615
base: master
Are you sure you want to change the base?
Add global setting for form submission message #1615
Conversation
WalkthroughThe changes introduce a new feature to handle form submission announcements in the Formidable Forms plugin. A new parameter for submission speech messages is added, enabling form accessibility improvement through auditory feedback. This feature includes the addition of a speak method in JavaScript, a new static method for retrieving messages in PHP, and an input field in the settings form for customizing the speak text. Changes
Sequence DiagramssequenceDiagram
participant User
participant FrmSettings
participant FrmFormsHelper
participant Form
participant JavaScript
User->>FrmSettings: Open settings
FrmSettings->>User: Display settings form
User->>FrmSettings: Update "Submit Speak Text"
FrmSettings->>FrmFormsHelper: Save $submit_speak_msg
User->>Form: Submit form
Form->>JavaScript: Trigger form submission
JavaScript->>JavaScript: Call "speak" method with message
JavaScript->>User: Announce form submission message
JavaScript->>Form: Proceed with form submission
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (3)
Additional context usedBiome
Additional comments not posted (3)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
js/formidable.js
Outdated
speak: function( message ) { | ||
var element = document.createElement( 'div' ); | ||
element.id = 'speak_formidable_form_submitted'; | ||
element.setAttribute( 'aria-live', 'assertive' ); | ||
element.className = 'frm_screen_reader frm_hidden'; | ||
element.textContent = message; | ||
document.body.appendChild( element ); | ||
|
||
setTimeout( | ||
function() { | ||
document.body.removeChild( element ); | ||
}, | ||
1000 | ||
); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor the speak
method to manage the temporary element more robustly, possibly by checking if the element still exists before attempting to remove it.
classes/helpers/FrmAppHelper.php
Outdated
@@ -3218,6 +3218,7 @@ public static function localize_script( $location ) { | |||
'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ), | |||
'focus_first_error' => self::should_focus_first_error(), | |||
'include_alert_role' => self::should_include_alert_role_on_field_errors(), | |||
'submit_speak_msg' => ( new FrmSettings() )->submit_speak_msg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the trailing tilde character.
- 3221~
+ 3221
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
'submit_speak_msg' => ( new FrmSettings() )->submit_speak_msg, | |
'submit_speak_msg' => ( new FrmSettings() )->submit_speak_msg, |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1615 +/- ##
============================================
+ Coverage 27.46% 29.58% +2.11%
+ Complexity 7916 7858 -58
============================================
Files 125 121 -4
Lines 26445 25954 -491
============================================
+ Hits 7264 7678 +414
+ Misses 19181 18276 -905 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am guessing this should get cut off when the form request is complete? I hear the text, but it stops after the form request is complete.
@garretlaxton I think you mistyped some words in your comment probably? I didn't get it well. |
@AbdiTolesa It sounds like the page exits before the message is read. I think we may be handling this from the wrong angle. I don't think we need to announce the submit event, but rather, the success event. If the confirmation action is a message, I think we could probably just add If there is a redirect action, we're probably fine to just not speak/add anything. |
@Crabcyborg Currently it looks the success message is announced without extra update, at least that's the default behaviour when i test with VoiceOver. But quoting the original issue description, I think the intention was more about the phase after Submit button is clicked when the form is being processed (spinner loading).
|
Thanks @AbdiTolesa! Maybe we can go with a shorter message. What you have is really long. I think just "Form submitted" is probably enough. |
Should I keep the new global setting to customise that or we should hard code it? Or probably make it customisable with a new filter? |
@AbdiTolesa I think just a new filter is fine. This feature doesn't need a lot of visibility. |
I have updated my code to just use a new filter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
js/formidable.js (1)
Line range hint
5-5
: Remove the redundant "use strict" directive.As modules are strict by default, this directive is unnecessary and can be safely removed to clean up the code.
- 'use strict';
/** | ||
* Returns the message announced when a form is submitted. | ||
* | ||
* @since x.x | ||
* | ||
* @return string | ||
*/ | ||
public static function get_submit_speak_message() { | ||
/** | ||
* Allows updating a message announced when a form is submitted. | ||
* | ||
* @since x.x | ||
* @param string $submit_speak_message | ||
*/ | ||
return apply_filters( 'frm_submit_speak_message', __( 'Form submitted', 'formidable' ) ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the @since
tag in the get_submit_speak_message
method is updated to reflect the actual version being released.
- * @since x.x
+ * @since 4.05 // Example version, replace with the actual version being released
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
/** | |
* Returns the message announced when a form is submitted. | |
* | |
* @since x.x | |
* | |
* @return string | |
*/ | |
public static function get_submit_speak_message() { | |
/** | |
* Allows updating a message announced when a form is submitted. | |
* | |
* @since x.x | |
* @param string $submit_speak_message | |
*/ | |
return apply_filters( 'frm_submit_speak_message', __( 'Form submitted', 'formidable' ) ); | |
} | |
/** | |
* Returns the message announced when a form is submitted. | |
* | |
* @since 4.05 // Example version, replace with the actual version being released | |
* | |
* @return string | |
*/ | |
public static function get_submit_speak_message() { | |
/** | |
* Allows updating a message announced when a form is submitted. | |
* | |
* @since x.x | |
* @param string $submit_speak_message | |
*/ | |
return apply_filters( 'frm_submit_speak_message', __( 'Form submitted', 'formidable' ) ); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Thanks @AbdiTolesa!
Fix https://github.com/Strategy11/formidable-pro/issues/3739
This PR adds a feature that announces a form submission message with screen reader when a form is submitted. There is also a new global setting added for updating the message.
Test steps: