Forms: Fix "Other" toggle not updating option label in editor#47316
Forms: Fix "Other" toggle not updating option label in editor#47316
Conversation
When toggling "Other" on via the per-option sidebar control, only isOther was set — the existing label was left unchanged, so an option labeled "Option B" would visually remain "Option B" despite being an "Other" option. Now the label is cleared when toggling on, letting the "Other" placeholder text take effect (matching the behavior of the parent-level "Include Other option" toggle). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
Pull request overview
This PR updates the Jetpack Forms option block editor behavior so “Other” radio options display the correct label/placeholder when toggled in the block sidebar.
Changes:
- Clear the option
labelwhen enabling the per-option "Other" option toggle so the placeholder can display. - Use the computed
placeholderValuefor the non-standaloneRichTextplaceholder (instead of a hardcodedAdd option…). - Add a patch changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| projects/packages/forms/src/blocks/option/edit.js | Updates “Other” toggle handling and ensures the editor uses the dynamic placeholder for option labels. |
| projects/packages/forms/changelog/fix-forms-other-option-label-reset | Adds a patch-level changelog entry for the editor fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| onChange={ value => | ||
| setAttributes( { | ||
| isOther: value, | ||
| label: value ? '' : label, | ||
| } ) | ||
| } |
There was a problem hiding this comment.
Toggling isOther on clears label, but it doesn’t adjust the placeholder attribute. If this block instance has a non-empty placeholder (many option blocks are created/migrated with placeholder: 'Add option…'), then placeholderValue will remain 'Add option…' even when isOther is true, so the option won’t display the expected “Other” label in the editor. Consider making the “Other” placeholder take precedence when isOther is enabled (e.g., set placeholder to '' or to the translated “Other” value when toggling on, or change the placeholderValue logic to ignore the default add-option placeholder when isOther is true).
| onChange={ value => | |
| setAttributes( { | |
| isOther: value, | |
| label: value ? '' : label, | |
| } ) | |
| } | |
| onChange={ value => { | |
| const newAttributes = { | |
| isOther: value, | |
| label: value ? '' : label, | |
| }; | |
| if ( value ) { | |
| newAttributes.placeholder = __( 'Other', 'jetpack-forms' ); | |
| } | |
| setAttributes( newAttributes ); | |
| } } |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
Follow-up of #46461 (fixes some regressions)
Proposed changes:
label: 'Other').placeholderValue(which switches between "Other" and "Add option…" based onisOther) for the non-standalone RichText placeholder, instead of a hardcoded "Add option…" string.Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Changelog