-
Notifications
You must be signed in to change notification settings - Fork 804
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
Contact Form Block: Prevent removal of the submit button #24838
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
db7cb15
set the lock attribute to remove the delete option from form buttons
vykes-mac 8c5b0f3
remove ability to delete form button on exisiting forms
vykes-mac 47fb77e
changelog
vykes-mac 3008e29
update existing contact form submit button only when jetpack form is …
vykes-mac 8196fd5
move logic to lock existing submit button to edit.js to prevent loadi…
vykes-mac 2829da2
Merge branch 'trunk' into update/disable-removal-submit-btn
coder-karen 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
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/disable-removal-form-submit-btn
This file contains 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,4 @@ | ||
Significance: patch | ||
Type: enhancement | ||
|
||
Prevent users from removing the contact form submit button. |
This file contains 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
This file contains 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
24 changes: 24 additions & 0 deletions
24
projects/plugins/jetpack/extensions/blocks/contact-form/view.js
This file contains 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,24 @@ | ||
import { dispatch, select, subscribe } from '@wordpress/data'; | ||
import domReady from '@wordpress/dom-ready'; | ||
|
||
if ( typeof window !== 'undefined' ) { | ||
domReady( () => { | ||
const getBlockList = () => select( 'core/block-editor' ).getBlocks(); | ||
const unsubscribe = subscribe( () => { | ||
const newBlockList = getBlockList(); | ||
const forms = newBlockList.filter( block => ( block.name = 'jetpack/contact-form' ) ); | ||
if ( forms.length > 0 ) { | ||
unsubscribe(); | ||
forms.forEach( form => { | ||
const button = form.innerBlocks.find( block => block.name === 'jetpack/button' ); | ||
if ( button ) { | ||
const lock = { move: false, remove: true }; | ||
dispatch( 'core/block-editor' ).updateBlockAttributes( button.clientId, { | ||
lock, | ||
} ); | ||
} | ||
} ); | ||
} | ||
} ); | ||
} ); | ||
} |
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.
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.
If you'd like to start loading js on the frontend whenever the form block is added to a post / page, you would need to also rely on
Jetpack_Gutenberg::load_assets_as_required()
in PHP to ensure the js gets loaded on the frontend.That said, I'm thinking we may not need to add this to the frontend, right? It should be enough to load this in the editor.
In this case, I would recommend that you move the code from
view.js
toedit.js
.This will have the added bonus of not having to load
@wordpress/data
on the frontend.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.
Yes this is not needed in the front-end only the editor. It's purpose is to update existing form blocks to remove the delete option for the submit button.
Thank you for the suggestion, this make sense since this piece of code is not needed in the front-end. I will update accordingly.