mardi 31 mars 2015

reform JavaScript code into JQuery form


Vote count:

0




I'm new on javaScript ( also jquery ), I looking for "html 5 validation costume message " on web, finally I found this code snipped :



(function (exports) {
function valOrFunction(val, ctx, args) {
if (typeof val == "function") {
return val.apply(ctx, args);
} else {
return val;
}
}

function InvalidInputHelper(input, options) {
input.setCustomValidity(valOrFunction(options.defaultText, window, [input]));

function changeOrInput() {
if (input.value == "") {
input.setCustomValidity(valOrFunction(options.emptyText, window, [input]));
} else {
input.setCustomValidity("");
}
}

function invalid() {
if (input.value == "") {
input.setCustomValidity(valOrFunction(options.emptyText, window, [input]));
} else {
console.log("INVALID!"); input.setCustomValidity(valOrFunction(options.invalidText, window, [input]));
}
}

input.addEventListener("change", changeOrInput);
input.addEventListener("input", changeOrInput);
input.addEventListener("invalid", invalid);
}
exports.InvalidInputHelper = InvalidInputHelper;


})(window);


InvalidInputHelper(document.getElementById("email"), { defaultText: "Please enter an email address!", emptyText: "Please enter an email address!", invalidText: function (input) { return 'The email address "' + input.value + '" is invalid!'; } });


Visit Set custom HTML5 required field validation message


Now I wan't to rewrite it with jquery, can any buddy helped me ?


Thanks a lot,



asked 58 secs ago







reform JavaScript code into JQuery form

Aucun commentaire:

Enregistrer un commentaire