Search code examples
javascripthtmlvalidationfirefoxconstraint-validation-api

HTML Validation API returns an empty object in Firefox


The validity property of an HTML input does not seem to work in Firefox.

var input = $input.get(0);
console.log(input.validity)

This console log returns an empty object. It's working on Chrome and Safari and I think it's also suppose to work on Firefox if I look at that doc?

https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

Any ideas?


Solution

  • If it's appearing as an empty object, it's likely because only enumerable properties are being rendered, which ValidityState's properties don't seem to be in Firefox.

    But, you should still be able to access individual properties:

    console.log(input.validity.valid);   // true/false
    console.log(input.validity.tooLong); // true/false
    // etc.