contributte / live-form-validation

:no_entry: Nice client-side live form validation for Nette Forms.

Home Page:https://contributte.org/packages/contributte/live-form-validation.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validator max & min not working at the same time

matej116 opened this issue · comments

Both validators max and min are using the range validator, when the min and max validator are used at the same time. The range validator will fail on the first one since it is checking elem.validity.overflow/underflow flags and the error message of the first failed validator is issued.

This implementation of range validator would solve the issue:

range: function(elem, arg, val) {
		if (elem.type === 'number') {
			if ((elem.validity.rangeUnderflow && arg[0] !== null) || (elem.validity.rangeOverflow && arg[1] !== null)) {
				debugger;
				return false
			} else if (elem.validity.badInput) {
				return null;
			}
		}
		return Nette.isArray(arg) ?
			((arg[0] === null || parseFloat(val) >= arg[0]) && (arg[1] === null || parseFloat(val) <= arg[1])) : null;
	},

The only change is check for arg[0] !== null and arg[1] !== null.

Resolved via c3b82a9