craftcms / craftcms/cms

$primaryForm in the control panel doesn't block additional submit requests made

Open
#1,972 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity:minor
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
  1. Click 'New Entry' on the entries listing screen to get to a new entry edit screen
  2. Click 'Save and Continue Editing' after all required fields are filled out
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.