Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

pressButton on <button type="button"> incorrectly submits the form #1190

Open
arturog opened this issue Feb 20, 2019 · 3 comments · May be fixed by #1197
Open

pressButton on <button type="button"> incorrectly submits the form #1190

arturog opened this issue Feb 20, 2019 · 3 comments · May be fixed by #1197

Comments

@arturog
Copy link

arturog commented Feb 20, 2019

No description provided.

@arturog arturog changed the title pressButton on <button type="button pressButton on <button type="button"> incorrectly submits the form Feb 20, 2019
@arturog
Copy link
Author

arturog commented Feb 20, 2019

When pressing a <button type="button"> contained within a <form>, the form is incorrectly submitted.
<button type="button"> should not by default submit the form as per specs.

(I believe this is a jsdom problem...)

@arturog
Copy link
Author

arturog commented Feb 28, 2019

OK, I think the problem is in Zombie:

  1. when pressButton is called, the event is correctly dispatched

    zombie/src/index.js

    Lines 360 to 366 in bbcd5a6

    const eventType = ~MOUSE_EVENT_NAMES.indexOf(eventName) ? 'MouseEvents' : 'HTMLEvents';
    const event = this.document.createEvent(eventType);
    event.initEvent(eventName, true, true);
    target.dispatchEvent(event);
    if (selector.tagName === 'BUTTON' || selector.tagName == 'INPUT') selector._click(event);
    return this._wait(null, callback);
    }

  2. But after dispatching the event, we call _click, which submits the form always.

    zombie/src/dom/forms.js

    Lines 241 to 250 in bbcd5a6

    DOM.HTMLButtonElement.prototype._click = function(event) {
    if (event.defaultPrevented) return;
    const button = event.target;
    if (button.getAttribute('disabled'))
    return false;
    const form = button.form;
    if (form)
    return form._dispatchSubmitEvent(button);
    };

I think the correct place to disable the submission would be the _click function. @assaf if you're happy to put the check in _click I can send a small patch.

@assaf
Copy link
Owner

assaf commented Mar 18, 2019

Yes, please send a path

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants