@luftborn/custom-elements 2.11.3 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/index.js +21 -2
- package/demo/index.min.js +20 -1
- package/demo/index.min.js.map +1 -1
- package/dist/custom-form.d.ts +1 -0
- package/dist/custom-form.js +20 -1
- package/dist/custom-form.js.map +1 -1
- package/package.json +1 -1
- package/src/custom-form.ts +25 -1
package/demo/index.min.js
CHANGED
|
@@ -2305,10 +2305,26 @@ var CustomForm = /** @class */ (function () {
|
|
|
2305
2305
|
groupContainers.forEach(function (element) {
|
|
2306
2306
|
var dependentField = element.getAttribute('data-depends-on');
|
|
2307
2307
|
var dependentValue = element.getAttribute('data-dependent-value');
|
|
2308
|
+
var dependentValues;
|
|
2309
|
+
try {
|
|
2310
|
+
dependentValues = JSON.parse(dependentValue);
|
|
2311
|
+
}
|
|
2312
|
+
catch (e) {
|
|
2313
|
+
dependentValues = [dependentValue];
|
|
2314
|
+
}
|
|
2308
2315
|
var customElement = document.forms[0].querySelector("[name=\"" + dependentField + "\"]");
|
|
2309
2316
|
element.setAttribute("hidden", "");
|
|
2310
2317
|
customElement.onChange.on(function (event) {
|
|
2311
|
-
if (
|
|
2318
|
+
if (_this.groupShouldBeVisible(event.value, dependentValues)) {
|
|
2319
|
+
_this.showGroupAndItsDependencies(element);
|
|
2320
|
+
}
|
|
2321
|
+
else {
|
|
2322
|
+
_this.hideGroupAndItsDependencies(element);
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2325
|
+
customElement.onVisibilityChanged.on(function (event) {
|
|
2326
|
+
var elmentIsHidden = customElement.hasAttribute('hidden');
|
|
2327
|
+
if (_this.groupShouldBeVisible(customElement.value, dependentValues) && !elmentIsHidden) {
|
|
2312
2328
|
_this.showGroupAndItsDependencies(element);
|
|
2313
2329
|
}
|
|
2314
2330
|
else {
|
|
@@ -2317,6 +2333,9 @@ var CustomForm = /** @class */ (function () {
|
|
|
2317
2333
|
});
|
|
2318
2334
|
});
|
|
2319
2335
|
};
|
|
2336
|
+
CustomForm.prototype.groupShouldBeVisible = function (eventValue, dependentValue) {
|
|
2337
|
+
return dependentValue.some(function (value) { return eventValue === value || (Array.isArray(eventValue) && eventValue.indexOf(value) >= 0); });
|
|
2338
|
+
};
|
|
2320
2339
|
CustomForm.prototype.hideGroupAndItsDependencies = function (group) {
|
|
2321
2340
|
var _this = this;
|
|
2322
2341
|
var inputElementsInsideGroup = this.inputs.filter(function (input) { return _this.isDescendant(group, input); });
|