Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome cannot submit form with display:none

The Submit button on this form does nothing unless I remove style="display:none" from the template=row div. Why??

(The name of each form control is populated dynamically by javascript, however, to simplify troubleshooting, I ran the form without the javascript and the problem boils down to whether or not that display tag is there).

This is what Chrome console says:

bundleAn invalid form control with name='' is not focusable.
bundleAn invalid form control with name='label' is not focusable.
bundleAn invalid form control with name='unique' is not focusable

HTML:

<form method="POST" action="/add/bundle">
    <p>
        <input type="text" name="singular" placeholder="Singular Name" required>
        <input type="text" name="plural" placeholder="Plural Name" required>
    </p>

    <h4>Asset Fields</h4>

<div class="template-view" id="template_row" style="display:none">
    <input type="text" data-keyname="name" placeholder="Field Name">
    <input type="text" data-keyname="hint" placeholder="Hint">


    <select data-keyname="fieldtype" required>
        <option value="">Field Type...</option>
    </select>

    <input type="checkbox" data-keyname="required" value="true"> Required
    <input type="checkbox" data-keyname="search" value="true"> Searchable
    <input type="checkbox" data-keyname="readonly" value="true"> ReadOnly
    <input type="checkbox" data-keyname="autocomplete" value="true"> AutoComplete
    <input type="radio" data-keyname="label" value="label" name="label" required> Label
    <input type="radio" data-keyname="unique" value="unique" name="unique" required> Unique
    <button class="add" type="button">+</button>
    <button class="remove" type="button">-</button>
</div>

<div id="target_list"></div>

    <p><input type="submit" name="form.submitted" value="Submit" autofocus></p>

</form>
like image 755
MFB Avatar asked Aug 24 '11 23:08

MFB


People also ask

Does display None submit?

Setting style display none does not submit form.

Why is submit button not working?

Sometimes the problem is caused by old versions of the Javascript files, cached by your browser and can be fixed by clearing the browser cache. You can use the browser console of your browser for debugging. After the Javascript error is fixed, the submit button will automatically be enabled.

How do I validate a submit button?

The correct way is onclick="validate_activity();" and return false in validata_activity function, which will stop the default submit action.


2 Answers

The cause seems to be HTML 5 constraint validation - it's the require attribute. Chrome has started supporting this with it's recent versions.

Apparently it seems like this is a backward compatibility issue, but you can fix it with setting the formnovalidate attribute for your submit button.

I assume that this is actually a security feature that prevents submitting supposed user data by submitting manipulated, hidden content, this quote points in that direction:

If one of the controls is not being rendered (e.g. it has the hidden attribute set) then user agents may report a script error.

Your inputs are of type text, so their purpose is to let users enter data, submitting their content while hidden is something that a user probably wouldn't want.

If you still want to submit hidden inputs while using client validation, I would suggest using <input type="hidden"> instead - I could imagine that there is no error on validation there because they are intended to be invisible.

like image 172
emboss Avatar answered Oct 23 '22 04:10

emboss


I made a JSFiddle to explore your problem here, and I managed to fix it by adding checked to your radiobutton inputs like so: <input type="radio" data-keyname="label" value="label" name="label" required checked>. In your code above, the radio buttons are not checked, but since they are marked as required the form is failing validation and Chrome refuses to submit the form.

like image 43
S M Avatar answered Oct 23 '22 04:10

S M