The short answer is no, there is no way to “run” the default functionality for the html5 inline string before submitting the form, you can checkValidity() on certain inputs, but again does not work as you would like. If you do not want to submit the form after the verification is complete, without waiting for the default warning, you can still process this style by following these steps:
Please note: in forms that you do not want to apply CSS CSS styles, you can simply add the novalidate attribute to the form.
HTML:
<form name="login" id="loginForm" method="POST"> <input type="email" name="username" placeholder="Email"> <input type="password" name="password" placeholder="Password"> <input type="submit" value="LOG IN" class="hero left clearBoth"> </form>
If you are not using SCSS, I highly recommend exploring it, making it more manageable, easier to write, and less confusing. Note. In the sample script, I have the exact css to be compiled. I also included a bubble style example.
SCSS:
form:not([novalidate]) { input, textarea { &:required {background: transparent url('/../../images/icons/red_asterisk.png') no-repeat 98% center;} &:required:valid {background: transparent url('/../../images/icons/valid.png') no-repeat 98% center; @include box-shadow(0 0 5px
JAVASCRIPT:
Here we can do some fun things to use the default messages and inherit them inside your own bubble or error message box.
var form = $('form'); var item = form.find(':invalid').first(); var node = item.get(0); var pos = item.position(); var message = node.validationMessage || 'Invalid value.'; var bubble = $('<span/>').html('<span class="formHintBubble" style="left: ' + pos.left + 'px; top:' + pos.top + 'px;">' + message + '<div class="cross">X</div></span>').contents(); bubble.insertAfter(item);
DEMO:
http://jsfiddle.net/shannonhochkins/wJkVS/
Enjoy it and I hope that I will help others with HTML5 form validation as it is awesome and needs to go out!
Shannon
Shannon Hochkins May 14, '13 at 1:04 2013-05-14 01:04
source share