Safari is not acknowledging the "required" attribute. How to fix it?

Amir Bennasr picture Amir Bennasr · Sep 20, 2015 · Viewed 24.9k times · Source
<form id="customerForm">
    <label>
        First Name:
        <input id="firstName" required />
    </label>
    <label>
        Social Security Number:
        <input id="ssn" required pattern="^d{3}-d{2}-d{4}$"
            title="Expected pattern is ###-##-####" />
    </label>
    <input type="submit" />
</form>

When I try that document in Chrome, it accepts the conditions and shows the error, as expected.

But when I try that document in Safari, it shows no error.

Answer

J&#233;r&#233;mie Chazelle picture Jérémie Chazelle · Dec 4, 2015

At this time, Safari doesn't support the "required" input attribute. http://caniuse.com/#search=required

To use the 'required' attribute on Safari, You can use 'webshim'

1 - Download webshim

2 - Put this code :

<head>
    <script src="js/jquery.js"></script>

    <script src="js-webshim/minified/polyfiller.js"></script> 

    <script> 
        webshim.activeLang('en');
        webshims.polyfill('forms');
        webshims.cfg.no$Switch = true;
    </script>
</head>