Added new disabled function that allows easy control of disabling the element a template constructs.

This commit is contained in:
Matt Mo 2021-02-03 10:00:26 -08:00
parent 815b6d99bf
commit 2c9879a937

View File

@ -641,6 +641,39 @@ class IgniteTemplate {
return this.attribute("checked", value, converter);
}
/**
* Adds a disabled attribute and class to this template.
* @param {Boolean|IgniteProperty} value A value to determine whether or not the element should be marked as disable dor not.
* @param {*} converter Optional function that can convert the value if needed.
* @returns This ignite template so function calls can be chained.
*/
disabled(value, converter = null) {
if (value instanceof IgniteProperty) {
this.attribute("disabled", value, convert => {
convert = (converter != null ? converter(convert) : convert);
if (convert) {
return "disabled";
} else {
return null;
}
});
this.class(value, convert => {
convert = (converter != null ? converter(convert) : convert);
if (convert) {
return "disabled";
} else {
return null;
}
});
} else if (value) {
this.attribute("disabled", "disabled");
this.class("disabled");
}
return this;
}
/**
* Sets the type attribute of the element to be constructed by this template.
* @param {String|IgniteProperty} value The value to set for the type attribute of the element this template will construct.