Change validation to not rely on cached element value and instead extract the current value from the element.
This commit is contained in:
parent
c93e138c3f
commit
36f43805bd
@ -162,6 +162,23 @@ IgniteTemplate.prototype.validate = function (callback) {
|
||||
|
||||
//Register a new validator
|
||||
this._validators.push(() => {
|
||||
//Get the elements current value
|
||||
var type = this.element.hasAttribute("type") ? this.element.getAttribute("type").toLowerCase().trim() : null;
|
||||
|
||||
//Get the value from the element.
|
||||
var value = null;
|
||||
if (type == "checkbox") {
|
||||
value = this.element.checked;
|
||||
} else if (type == "radio") {
|
||||
value = this.element.checked;
|
||||
} else if (type == "number") {
|
||||
value = Number(this.element.value);
|
||||
} else if (this.element.hasAttribute("contenteditable") && this.element.getAttribute("contenteditable").toLowerCase().trim() == "true") {
|
||||
value = this.element.textContent;
|
||||
} else {
|
||||
value = this.element.value;
|
||||
}
|
||||
|
||||
//If the element already has a validation element remove it.
|
||||
if (this.element._validation && this.element._validation.isConnected) {
|
||||
this.element._validation.remove();
|
||||
@ -177,7 +194,7 @@ IgniteTemplate.prototype.validate = function (callback) {
|
||||
//Run the target to see if we passed validation.
|
||||
var error = false;
|
||||
target(
|
||||
this._elementValue,
|
||||
value,
|
||||
(msg, duration = 4000) => { notify(this.element, "error", msg, duration); error = true; },
|
||||
(msg, duration = 4000) => { notify(this.element, "warning", msg, duration); },
|
||||
(msg, duration = 4000) => { notify(this.element, "success", msg, duration); },
|
||||
|
Loading…
x
Reference in New Issue
Block a user