bootstrap-validator
bootstrap-validator copied to clipboard
Hidden fields
Hi,
I have a form which includes a modal/ajax upload of a file, the result of which is to update a field with a mediaId. I need to make sure the user has uploaded an image so I added required to the hidden field as follows:
<div class="form-group">
<input id="mediaId" name="mediaId" required="true" type="hidden" value=""/>
<div class="help-block with-errors"></div>
</div>
But unfortunately, no error message is shown and the user can submit the form. How to tack?
I have a similar issue and it looks like it's not working at all inside a modal window. It does work with onblur() but submit event is not prevented
+1
+1, this is also the browser behavior: https://jsfiddle.net/kwtzktn3/ If you send the form, it doesn't give you any validation warnings in chrome.
You need to change the INPUT_SELECTOR
the plugin uses to determine what types of fields to check. By default, it excludes [type="hidden"]
fields.
$.fn.validator.Constructor.INPUT_SELECTOR = ':input:not([type="submit"], [type="reset"], button)'
According to the documentation, adding data-validate="true"
should also work. But it doesn't.
See #333