From d02aed7787ab1478f546530699d22b6445f0921d Mon Sep 17 00:00:00 2001 From: Jan Piskvor Martinec Date: Sat, 12 Nov 2016 03:40:12 +0100 Subject: [PATCH] For number type, use the user-defined validation text The JS library always uses a hardcoded error text if a type="number" field is misfilled. It should only fall back to the hardcoded text if no error message has been defined. --- src/assets/netteForms.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/assets/netteForms.js b/src/assets/netteForms.js index fc97eec15..1224e00a0 100644 --- a/src/assets/netteForms.js +++ b/src/assets/netteForms.js @@ -187,6 +187,15 @@ Nette.validateControl = function(elem, rules, onlyCheck, value, emptyOptional) { Nette.addError(curElem, message); } return false; + } else if (elem.type === 'number' && !elem.validity.valid) { + if (!onlyCheck) { + var arr = Nette.isArray(rule.arg) ? rule.arg : [rule.arg], + message = rule.msg.replace(/%(value|\d+)/g, function(foo, m) { + return Nette.getValue(m === 'value' ? curElem : elem.form.elements.namedItem(arr[m].control)); + }); + Nette.addError(curElem, message); + } + return false; } }