From e4a521f1b9164eeccc0721fefef1a320dcbff54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hrani=C4=8Dka?= Date: Wed, 18 Feb 2015 22:35:18 +0100 Subject: [PATCH 1/2] netteForms.js: Set validation result CSS classes --- src/assets/netteForms.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/assets/netteForms.js b/src/assets/netteForms.js index 4604394dc..2658af54f 100644 --- a/src/assets/netteForms.js +++ b/src/assets/netteForms.js @@ -127,6 +127,7 @@ Nette.validateControl = function(elem, rules, onlyCheck, value) { if (rule.condition && success) { if (!Nette.validateControl(elem, rule.rules, onlyCheck, value)) { + Nette.markControlInvalid(elem); return false; } } else if (!rule.condition && !success) { @@ -140,13 +141,35 @@ Nette.validateControl = function(elem, rules, onlyCheck, value) { }); Nette.addError(curElem, message); } + Nette.markControlInvalid(elem); return false; } } + Nette.markControlValid(elem); return true; }; +Nette.markControlValid = function(elem) { + Nette.switchClass(elem, 'control-invalid', 'control-valid'); +}; + + +Nette.markControlInvalid = function(elem) { + Nette.switchClass(elem, 'control-valid', 'control-invalid'); +}; + + +Nette.switchClass = function(elem, remove, add) { + if (typeof elem.classList === 'undefined') { // not supported in IE < 10 , Opera Mini 8 + return; + } + + elem.classList.remove(remove); + elem.classList.add(add); +}; + + /** * Validates whole form. */ From 8052e440b07bc6f085ed90843045f0d03650bf8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hrani=C4=8Dka?= Date: Wed, 18 Feb 2015 23:14:54 +0100 Subject: [PATCH 2/2] netteForms.js: nette namespace added to CSS classes --- src/assets/netteForms.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assets/netteForms.js b/src/assets/netteForms.js index 2658af54f..36be81ea4 100644 --- a/src/assets/netteForms.js +++ b/src/assets/netteForms.js @@ -151,12 +151,12 @@ Nette.validateControl = function(elem, rules, onlyCheck, value) { Nette.markControlValid = function(elem) { - Nette.switchClass(elem, 'control-invalid', 'control-valid'); + Nette.switchClass(elem, 'nette-control-invalid', 'nette-control-valid'); }; Nette.markControlInvalid = function(elem) { - Nette.switchClass(elem, 'control-valid', 'control-invalid'); + Nette.switchClass(elem, 'nette-control-valid', 'nette-control-invalid'); };