I am having a problem with the HTML5 validation on Opera and Safari.
In Opera, the message bubble it's not displaying any text, and in safari the validation does not occur when i press the submit button. In IE, Mozilla or Chrome the validation works just fine. Could anyone tell why is this happening?
The inputs that i have in my forms have the html5 standard validation, with the required attribute, and that's it.
I tried to search this topic around the web, but didn't manage to find it.
Please help me.
Thanks
<form class="sign-in-form" action="" method="post">
<li>
<label>
<span>Username</span>
<input placeholder="Please enter your username" name="username" type="text" tabindex="1" title="It must contain the username that you have chosen at registration" required autofocus>
</label>
</li>
<li>
<label>
<span>Password</span>
<input placeholder="Please enter your password" name="password" type="password" tabindex="2" title="It must contain the password that you have chosen at registration" required>
</label>
</li>
<li>
<button name="sign-in-btn" type="submit" id="sign-in-submit">Sign In</button>
</li>
</form>
To ignore HTML validation, you can remove the attribute on button click using JavaScript. Uer removeAttribute() to remove an attribute from each of the matched elements.
Short Answer. Yes the standard HTML5 validation is accessible and will pass WCAG2. 1 AA, but you can do a lot better with some JavaScript.
on('click', function(event) { var isvalidate = $("#formID")[0]. checkValidity(); if (isvalidate) { event. preventDefault(); // HERE YOU CAN PUT YOUR AJAX CALL } }); }); Code described above will allow You to use basic HTML5 validation (with type and pattern matching) WITHOUT submitting form.
HTML 5 client side validations are a very useful feature: they allow rudimentary validation of user data without submitting anything to the server. They are supported to a high degree by modern browsers and screen readers.
It's a weird bug in opera: the message is not displayed when using @font-face web fonts. I also experienced this problem. Choosing a normal font like Arial, the message gets displayed. Safari doesn't support html5 validation (safari has partly support but there is no validation bubble). My tip is: use webshims lib (http://afarkas.github.io/webshim/demos/) - great polyfill for many features like validation.
I had the same problem and solved it in this way
<script>
(function() {
var loadScript = function(src, loadCallback) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = src;
s.onload = loadCallback;
document.body.appendChild(s);
};
// http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
if (isSafari || isOpera) {
loadScript('//code.jquery.com/jquery-2.1.4.min.js', function () {
loadScript('//cdnjs.cloudflare.com/ajax/libs/webshim/1.15.10/dev/polyfiller.js', function () {
webshims.setOptions('forms', {
overrideMessages: true,
replaceValidationUI: false
});
webshims.setOptions({
waitReady: true
});
webshims.polyfill();
});
});
}
})();
</script>
Just add this snipped at the end of your page. You can remove the load jQuery step if you already have imported it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With