Improve handling of the 'controls' argument
This commit is contained in:
parent
2679c5898e
commit
db22a8e9c4
23
src/js/controls.js
vendored
23
src/js/controls.js
vendored
@ -1117,11 +1117,6 @@ const controls = {
|
|||||||
// Build the default HTML
|
// Build the default HTML
|
||||||
// TODO: Set order based on order in the config.controls array?
|
// TODO: Set order based on order in the config.controls array?
|
||||||
create(data) {
|
create(data) {
|
||||||
// Do nothing if we want no controls
|
|
||||||
if (is.empty(this.config.controls)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the container
|
// Create the container
|
||||||
const container = createElement('div', getAttributesFromSelector(this.config.selectors.controls.wrapper));
|
const container = createElement('div', getAttributesFromSelector(this.config.selectors.controls.wrapper));
|
||||||
|
|
||||||
@ -1401,13 +1396,19 @@ const controls = {
|
|||||||
};
|
};
|
||||||
let update = true;
|
let update = true;
|
||||||
|
|
||||||
if (is.string(this.config.controls) || is.element(this.config.controls)) {
|
// If function, run it and use output
|
||||||
// String or HTMLElement passed as the option
|
if (is.function(this.config.controls)) {
|
||||||
|
this.config.controls = this.config.controls.call(this.props);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert falsy controls to empty array (primarily for empty strings)
|
||||||
|
if (!this.config.controls) {
|
||||||
|
this.config.controls = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is.element(this.config.controls) || is.string(this.config.controls)) {
|
||||||
|
// HTMLElement or Non-empty string passed as the option
|
||||||
container = this.config.controls;
|
container = this.config.controls;
|
||||||
} else if (is.function(this.config.controls)) {
|
|
||||||
// A custom function to build controls
|
|
||||||
// The function can return a HTMLElement or String
|
|
||||||
container = this.config.controls.call(this, props);
|
|
||||||
} else {
|
} else {
|
||||||
// Create controls
|
// Create controls
|
||||||
container = controls.create.call(this, {
|
container = controls.create.call(this, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user