cferdinandi / validate

A lightweight form validation script.
MIT License
230 stars 39 forks source link

Switch to a loop for support test #21

Closed cferdinandi closed 6 years ago

cferdinandi commented 7 years ago
var validityObjProperties = ["badInput", "patternMismatch", "rangeOverflow", "rangeUnderflow", "stepMismatch", "tooLong", "tooShort", "typeMismatch", "valid", "valueMissing"];

var supported = function () {
      var input = document.createElement('input');
      if('validity' in input) {
        var supportObj = { lackSupport: false, unsupportedProps: [] };
        for(var i = 0; i < validityObjProperties.length; i++) {
          var validityProp = validityObjProperties[i];
          var isPropSupported = validityProp in input;
           if(!isPropSupported) { 
              supportObj.lackSupport = true;
              supportObj.unsupportedProps.push(validityProp);
           }
        }
      }

  return supportObj;
};

Via Konstantin

cferdinandi commented 6 years ago

Changed my mind