$primaryForm in the control panel doesn't block additional submit requests made
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
Description
Primary Form in the control panel doesn't block additional submit requests made. This can result in multiple entries being created on first save if a save button is clicked more than once.
Steps to reproduce
- Click 'New Entry' on the entries listing screen to get to a new entry edit screen
- Click 'Save and Continue Editing' after all required fields are filled out
- Click the 'Save' button before the last request has completed
Additional info
- Craft version: 2.6.2989
- PHP version: 7.0.10
Temporary Fix
The code below included from a plugin fixes the issue, although I am not sure if this would cause any unintended consequences and would probably want to be rolled into cp.js.
jQuery(function($){
if( Craft && Craft.cp && Craft.cp.$primaryForm ){
Craft.cp.$primaryForm.on('submit',function(ev){
var $form = $(this);
if( $form.hasClass('submitting') ){
ev.preventDefault();
return false;
}
$form.addClass('submitting');
$form.find('button[type=submit],input[type=submit]').prop('disabled',true).addClass('disabled');
$form.find('.submit.menubtn').addClass('disabled').blur().data('menubtn').disable();
});
}
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining cp.js and the Craft.cp.$primaryForm submit handling described in the issue. Reproduce the control-panel entry flow by using “Save and Continue Editing” followed quickly by “Save”; done means the second request is prevented and submit controls are disabled while the first request is pending.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100