jquery-ujs icon indicating copy to clipboard operation
jquery-ujs copied to clipboard

Remote forms with blank required field still submitting.

Open ericdfields opened this issue 10 years ago • 2 comments

I've got one required field in my remote form. It's a select field. If I don't select something and try to submit, it still does an ajax post. Clearly visible in Inspector > Networks.

From what I've read, the ajax:aborted:required event should be fired and the form should not submit. Am I wrong?

I've tried binding to that event and it doesn't seem to get fired.

Here's a basic cross-section of my form with all the useful details:

<form action="/object/123" data-remote="true" method="post">
  <select required="required">
    <option>option 1</option>
    <option>option 2</option>
    <option>option 2</option>
  </select>
  <input type="submit" value="Save">
</form>

Thanks for any help.

ericdfields avatar Mar 25 '15 17:03 ericdfields

required select has one particularity. To it be valid you need a blank option. I don't know if we should check too. http://www.w3.org/TR/html5/forms.html#the-select-element

rafaelfranca avatar Mar 25 '15 20:03 rafaelfranca

I see. That does complicate things, but it seems like it'd be worth it. I think we'd have to adjust the logic here?

ericdfields avatar Mar 25 '15 20:03 ericdfields