Html5 required attribute for unsupported browsers

I have a web application that often uses the HTML5 required attribute. However, Safari, etc. 8/9 do not support this attribute. Is there a jQuery plugin that will force incompatible browsers to behave?

+6
source share
5 answers

I found a very versatile and lightweight (once miniature) engine that works cross-browser, including ie8!

http://posabsolute.imtqy.com/jQuery-Validation-Engine/

-1
source

This works without any plugin (jQuery only):

 <script> // fix for IE < 11 if ($("<input />").prop("required") === undefined) { $(document).on("submit", function(e) { $(this) .find("input, select, textarea") .filter("[required]") .filter(function() { return this.value == ''; }) .each(function() { e.preventDefault(); $(this).css({ "border-color":"red" }); alert( $(this).prev('label').html() + " is required!"); }); }); } </script> 
+7
source

You can just flash it ...

 if ($("<input />").prop("required") === undefined) { $(document).on("submit", function(event) { $(this) .find("input, select, textarea") .filter("[required]") .filter(function() { return this.value; }) .each(function() { // Handle them. }); }); } 
+4
source

You can use h5validate , which does exactly what you need.

 <script> $(document).ready(function () { $('form').h5Validate(); }); </script> 
+2
source

I wrote a simple jQuery plugin for this. It simply adds client-side validation to the forms using the "required" attribute.

https://github.com/garyv/jQuery-Validation-plugin

After you enable the plugin, you can call validate () in the jQuery document ready function or at the end of the html body.

 <script> $(document).ready(function(){ $('form').validate(); }); </script> 
+2
source

Source: https://habr.com/ru/post/948750/


All Articles