-
Notifications
You must be signed in to change notification settings - Fork 92
gpadvs-dropdown-remove-button.js: Added snippet to show remove button on Dropdown fields.
#1028
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef7aba0
`gpadvs-dropdown-remove-button.js`: Added snippet to show remove butt…
veryspry 0de9613
`gpadvs-dropdown-remove-button.js`: Added Tom Select remove button pl…
veryspry 793d79e
`gpadvs-dropdown-remove-button.js`: Added snippet to show "Clear" but…
veryspry 8752ed8
`gpadvs-dropdown-remove-button.js`: Added conditional showing how to …
veryspry 148b7c5
`gpadvs-dropdown-remove-button.js`: Updated documentation comment.
veryspry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Gravity Perks // Advanced Select // Clear Button | ||
| * https://gravitywiz.com/documentation/gravity-forms-advanced-select/ | ||
| * | ||
| * Adds a Clear buton to GP Advanced Select fields. | ||
| * | ||
| * The Clear Button is a built in plugin of Tom Select. | ||
| * @reference https://tom-select.js.org/plugins/clear-button/ | ||
| * | ||
| * Instructions: | ||
| * | ||
| * 1. Install this snippet with our free Custom JavaScript plugin. | ||
| * https://gravitywiz.com/gravity-forms-code-chest/ | ||
| */ | ||
| window.gform.addFilter( | ||
| 'gpadvs_settings', | ||
| function(settings, gpadvsInstance, selectNamespace) { | ||
| /** | ||
| * Scope to only dropdown fields. | ||
| * This can also be changed to 'multiselect' to only target multi-select fields | ||
| * OR the conditional can be removed to apply to all fields. | ||
| */ | ||
| if (gpadvsInstance.fieldType === 'dropdown') { | ||
| settings.plugins.clear_button = { | ||
| title: 'Clear options', | ||
| }; | ||
| } | ||
|
|
||
| return settings; | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * Gravity Perks // Advanced Select // Dropdown Remove Button | ||
| * https://gravitywiz.com/documentation/gravity-forms-advanced-select/ | ||
| * | ||
| * Adds a Remove button to selection options in Dropdown fields. By default, | ||
| * the remove button is only added to Multi-Select fields. | ||
| * | ||
| * The Remove Button is a built in plugin of Tom Select. | ||
| * @reference https://tom-select.js.org/plugins/remove-button/ | ||
| * | ||
| * Instructions: | ||
| * | ||
| * 1. Install this snippet with our free Custom JavaScript plugin. | ||
| * https://gravitywiz.com/gravity-forms-code-chest/ | ||
| */ | ||
| window.gform.addFilter( | ||
| 'gpadvs_settings', | ||
| function(settings, gpadvsInstance, selectNamespace) { | ||
| settings.plugins.remove_button = { | ||
| title: window.GPADVS.strings?.remove_this_item | ||
| ? window.GPADVS.strings.remove_this_item | ||
| : 'Remove this item', | ||
| } | ||
|
|
||
| return settings; | ||
| } | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Documentation and implementation mismatch.
The documentation states this adds a Remove button to Dropdown fields and is only added to Multi-Select fields by default. However, the implementation applies to all field types without any conditional check (unlike the clear-button implementation).
Either update the documentation to match the implementation or add a conditional check similar to the clear-button implementation:
function(settings, gpadvsInstance, selectNamespace) { + /** + * Scope to only multi-select fields. + * This conditional can be modified to target different field types. + */ + if (gpadvsInstance.fieldType === 'multiselect') { settings.plugins.remove_button = { title: window.GPADVS.strings?.remove_this_item ? window.GPADVS.strings.remove_this_item : 'Remove this item', } + } return settings; }📝 Committable suggestion
Uh oh!
There was an error while loading. Please reload this page.
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.
Nice one, code rabbit :finger-guns. Updated ✅
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.
@veryspry Thank you for implementing the suggested change! This will ensure the implementation aligns with the documentation and targets only multi-select fields as intended.
(\ /)
(・ᴗ・)
/ >🥕