not-bulma 1.0.53 → 1.0.54
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/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import notBase from "../../base";
|
|
|
8
8
|
import UICommon from "../../../elements/common.js";
|
|
9
9
|
import FormHelpers from "./form.helpers.js";
|
|
10
10
|
import UIFormComponent from "./form.svelte";
|
|
11
|
+
import notFormRules from "./form.rules.js";
|
|
11
12
|
|
|
12
13
|
import { DEFAULT_STATUS_SUCCESS, DEFAULT_STATUS_ERROR } from "../../const";
|
|
13
14
|
|
|
@@ -141,6 +142,34 @@ class notForm extends notBase {
|
|
|
141
142
|
this.#form.$on("submit", (ev) => this.submit(ev.detail));
|
|
142
143
|
this.#form.$on("reject", () => this.reject());
|
|
143
144
|
this.#form.$on("error", ({ detail }) => this.emit("error", detail));
|
|
145
|
+
this.#bindMasterSlaveEvents();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#bindMasterSlaveEvents() {
|
|
149
|
+
const masters = this.getOptions("masters", false);
|
|
150
|
+
if (!masters) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
for (let master in masters) {
|
|
154
|
+
const rules = masters[master];
|
|
155
|
+
for (let ruleName in rules) {
|
|
156
|
+
const ruleSlaves = rules[ruleName];
|
|
157
|
+
this.#addMasterSlaveEvents(ruleName, master, ruleSlaves);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#addMasterSlaveEvents(rule, master, slaves = []) {
|
|
163
|
+
this.on(`change.${master}`, (value) => {
|
|
164
|
+
this.#execSlaveRule(rule, slaves, value);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#execSlaveRule(rule, slaves, value) {
|
|
169
|
+
const cmd = notFormRules.exec(rule, value);
|
|
170
|
+
slaves.forEach((slaveField) => {
|
|
171
|
+
this.updateField(slaveField, cmd);
|
|
172
|
+
});
|
|
144
173
|
}
|
|
145
174
|
|
|
146
175
|
async validateForm() {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const DEFAULT_RULES = {
|
|
2
|
+
notReadonly(v) {
|
|
3
|
+
return {
|
|
4
|
+
readonly: !v,
|
|
5
|
+
};
|
|
6
|
+
},
|
|
7
|
+
readonly(v) {
|
|
8
|
+
return {
|
|
9
|
+
readonly: v,
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
enable(v) {
|
|
13
|
+
return {
|
|
14
|
+
disabled: !v,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
disable(v) {
|
|
18
|
+
return {
|
|
19
|
+
disabled: v,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default class notFormRules {
|
|
25
|
+
static #RULES = { ...DEFAULT_RULES };
|
|
26
|
+
|
|
27
|
+
static add(name, func) {
|
|
28
|
+
if (!Object.hasOwn(this.#RULES, name)) {
|
|
29
|
+
this.#RULES[name] = func;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static remove(name) {
|
|
34
|
+
if (
|
|
35
|
+
Object.hasOwn(this.#RULES, name) &&
|
|
36
|
+
!Object.keys(DEFAULT_RULES).includes(name)
|
|
37
|
+
) {
|
|
38
|
+
delete this.#RULES[name];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static exec(name, value) {
|
|
43
|
+
return this.#RULES[name](value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import notFormUtils from "./utils";
|
|
2
2
|
import notFormHelpers from "./form.helpers";
|
|
3
3
|
import notForm from "./form";
|
|
4
|
+
import notFormRules from "./form.rules";
|
|
4
5
|
import notFormSet from "./form.set";
|
|
5
6
|
import UIForm from "./form.svelte";
|
|
6
7
|
|
|
7
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
UIForm,
|
|
10
|
+
notForm,
|
|
11
|
+
notFormRules,
|
|
12
|
+
notFormSet,
|
|
13
|
+
notFormUtils,
|
|
14
|
+
notFormHelpers,
|
|
15
|
+
};
|
|
@@ -4,6 +4,7 @@ import notActionUI from "./action/action.ui.js";
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
notForm,
|
|
7
|
+
notFormRules,
|
|
7
8
|
notFormSet,
|
|
8
9
|
notFormUtils,
|
|
9
10
|
notFormHelpers,
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
notTable,
|
|
20
21
|
UIForm,
|
|
21
22
|
notForm,
|
|
23
|
+
notFormRules,
|
|
22
24
|
notFormSet,
|
|
23
25
|
notFormUtils,
|
|
24
26
|
notFormHelpers,
|