Change the word 'number' to 'integer' in number field message
The error message of number fields is different, some use 'integer', the other use 'number', it may be a good idea to change them to the same word.
Besides, I deduplicated the code that prevent user to input 'E' or 'e'
@@ -670,6 +670,17 @@ function registerMinMaxValidator(e) {
e = null; // avoid memory leak
}
+
+/**
+ * Prevent user input 'e' or 'E' in <f:number>
+ * @param event Input event
+ */
+function preventInputEe(event) {
+ if (event.which === 69 || event.which === 101) {
+ event.preventDefault();
+ }
+}
+
/**
* Wraps a <button> into YUI button.
*
@@ -960,51 +971,31 @@ function rowvgStartEachRow(recursive,f) {
// validate form values to be an integer
Behaviour.specify("INPUT.number", "input-number", ++p, function(e) {
- e.addEventListener('keypress', function (event) {
- if (event.which === 69 || event.which === 101) { // Prevent user input 'e' or 'E'
- event.preventDefault();
- }
- })
+ e.addEventListener('keypress', preventInputEe)
registerMinMaxValidator(e);
registerRegexpValidator(e,/^((\-?\d+)|)$/,"Not an integer");
});
Behaviour.specify("INPUT.number-required", "input-number-required", ++p, function(e) {
- e.addEventListener('keypress', function (event) {
- if (event.which === 69 || event.which === 101) { // Prevent user input 'e' or 'E'
- event.preventDefault();
- }
- })
+ e.addEventListener('keypress', preventInputEe)
registerMinMaxValidator(e);
registerRegexpValidator(e,/^\-?(\d+)$/,"Not an integer");
});
Behaviour.specify("INPUT.non-negative-number-required", "input-non-negative-number-required", ++p, function(e) {
- e.addEventListener('keypress', function (event) {
- if (event.which === 69 || event.which === 101) { // Prevent user input 'e' or 'E'
- event.preventDefault();
- }
- })
+ e.addEventListener('keypress', preventInputEe)
registerMinMaxValidator(e);
- registerRegexpValidator(e,/^\d+$/,"Not a non-negative number");
+ registerRegexpValidator(e,/^\d+$/,"Not a non-negative integer");
});
Behaviour.specify("INPUT.positive-number", "input-positive-number", ++p, function(e) {
- e.addEventListener('keypress', function (event) {
- if (event.which === 69 || event.which === 101) { // Prevent user input 'e' or 'E'
- event.preventDefault();
- }
- })
+ e.addEventListener('keypress', preventInputEe)
registerMinMaxValidator(e);
registerRegexpValidator(e,/^(\d*[1-9]\d*|)$/,"Not a positive integer");
});
Behaviour.specify("INPUT.positive-number-required", "input-positive-number-required", ++p, function(e) {
- e.addEventListener('keypress', function (event) {
- if (event.which === 69 || event.which === 101) { // Prevent user input 'e', 'E', '.'
- event.preventDefault();
- }
- })
+ e.addEventListener('keypress', preventInputEe)
registerMinMaxValidator(e);
registerRegexpValidator(e,/^[1-9]\d*$/,"Not a positive integer");
});
