@pageboard/html 0.12.20 → 0.12.21
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/elements/form.js +25 -13
- package/package.json +1 -1
- package/ui/form.css +7 -2
- package/ui/form.js +19 -4
package/elements/form.js
CHANGED
|
@@ -12,6 +12,12 @@ exports.query_form = {
|
|
|
12
12
|
format: 'id',
|
|
13
13
|
nullable: true
|
|
14
14
|
},
|
|
15
|
+
masked: {
|
|
16
|
+
title: 'Masked',
|
|
17
|
+
description: 'Hidden and disabled, unmasked by $query.toggle',
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
default: false
|
|
20
|
+
},
|
|
15
21
|
type: {
|
|
16
22
|
title: 'Bind to element',
|
|
17
23
|
description: 'Checks schema and helps adding form controls',
|
|
@@ -46,8 +52,8 @@ exports.query_form = {
|
|
|
46
52
|
},
|
|
47
53
|
contents: 'block+',
|
|
48
54
|
tag: 'form[method="get"]',
|
|
49
|
-
html: `<form is="element-form" method="get" name="[name]"
|
|
50
|
-
action="[redirection|
|
|
55
|
+
html: `<form is="element-form" method="get" name="[name]" masked="[masked]"
|
|
56
|
+
action="[redirection.url][redirection.parameters|as:query]"
|
|
51
57
|
autocomplete="off" class="ui form"></form>`,
|
|
52
58
|
stylesheets: [
|
|
53
59
|
'../lib/components/form.css',
|
|
@@ -72,18 +78,24 @@ exports.api_form = {
|
|
|
72
78
|
'data.action.parameters': 'webmaster'
|
|
73
79
|
},
|
|
74
80
|
properties: {
|
|
81
|
+
name: {
|
|
82
|
+
title: 'Name',
|
|
83
|
+
description: '<action>=<name> where action=submit or toggle',
|
|
84
|
+
type: 'string',
|
|
85
|
+
format: 'id',
|
|
86
|
+
nullable: true
|
|
87
|
+
},
|
|
75
88
|
hidden: {
|
|
76
89
|
title: 'Hidden',
|
|
77
90
|
type: 'boolean',
|
|
78
91
|
default: false,
|
|
79
92
|
context: 'template'
|
|
80
93
|
},
|
|
81
|
-
|
|
82
|
-
title: '
|
|
83
|
-
description: '
|
|
84
|
-
type: '
|
|
85
|
-
|
|
86
|
-
nullable: true
|
|
94
|
+
masked: {
|
|
95
|
+
title: 'Masked',
|
|
96
|
+
description: 'Hidden and disabled, unmasked by $query.toggle',
|
|
97
|
+
type: 'boolean',
|
|
98
|
+
default: false
|
|
87
99
|
},
|
|
88
100
|
action: {
|
|
89
101
|
title: 'Action',
|
|
@@ -166,13 +178,13 @@ exports.api_form = {
|
|
|
166
178
|
},
|
|
167
179
|
contents: 'block+',
|
|
168
180
|
tag: 'form[method="post"]',
|
|
169
|
-
html: `<form is="element-form" method="post" name="[name]"
|
|
181
|
+
html: `<form is="element-form" method="post" name="[name]" masked="[masked]"
|
|
170
182
|
action="/.api/form/[$id]"
|
|
171
183
|
parameters="[$expr?.action?.parameters|templates:$query]"
|
|
172
|
-
success="[redirection|
|
|
173
|
-
badrequest="[badrequest|
|
|
174
|
-
unauthorized="[unauthorized|
|
|
175
|
-
notfound="[notfound|
|
|
184
|
+
success="[redirection.url][redirection.parameters|as:query]"
|
|
185
|
+
badrequest="[badrequest.url][badrequest.parameters|as:query]"
|
|
186
|
+
unauthorized="[unauthorized.url][unauthorized.parameters|as:query]"
|
|
187
|
+
notfound="[notfound.url][notfound.parameters|as:query]"
|
|
176
188
|
class="ui form [hidden]"></form>`,
|
|
177
189
|
stylesheets: [
|
|
178
190
|
'../lib/components/form.css',
|
package/package.json
CHANGED
package/ui/form.css
CHANGED
|
@@ -37,6 +37,11 @@ element-select {
|
|
|
37
37
|
position:relative;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
.ui.form[method="post"]
|
|
41
|
-
|
|
40
|
+
.ui.form[method="post"].unsaved button[type="submit"] {
|
|
41
|
+
text-decoration:underline;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[contenteditable] form[hidden] {
|
|
45
|
+
display: block !important;
|
|
46
|
+
opacity:0.5;
|
|
42
47
|
}
|
package/ui/form.js
CHANGED
|
@@ -103,10 +103,17 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
103
103
|
}
|
|
104
104
|
patch(state) {
|
|
105
105
|
if (state.scope.$write) return;
|
|
106
|
+
const { submit, toggle } = state.query;
|
|
107
|
+
const toggles = [];
|
|
108
|
+
if (typeof toggle == "string") toggles.push(...toggle.split('-'));
|
|
109
|
+
else if (Array.isArray(toggle)) toggles.push(...toggle);
|
|
110
|
+
|
|
111
|
+
const masked = this.hasAttribute('masked');
|
|
112
|
+
|
|
106
113
|
if (this.method != "get") {
|
|
107
114
|
// ?submit=<name> for auto-submit
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
if (submit && submit == this.name) {
|
|
116
|
+
if (masked) toggles.push(submit);
|
|
110
117
|
state.vars.submit = true;
|
|
111
118
|
}
|
|
112
119
|
const vars = state.templatesQuery(this) || {};
|
|
@@ -120,6 +127,13 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
120
127
|
state.vars[name] = true;
|
|
121
128
|
}
|
|
122
129
|
}
|
|
130
|
+
if (toggles.includes(this.name)) {
|
|
131
|
+
// ?toggle=<name> for toggling hidden state
|
|
132
|
+
if (toggle) state.vars.toggle = true;
|
|
133
|
+
this.disabled = this.hidden = !masked;
|
|
134
|
+
} else if (this.name) {
|
|
135
|
+
this.disabled = this.hidden = masked;
|
|
136
|
+
}
|
|
123
137
|
}
|
|
124
138
|
paint(state) {
|
|
125
139
|
// ?submit=<name> for auto-submit
|
|
@@ -355,14 +369,15 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
355
369
|
form.classList.remove('loading');
|
|
356
370
|
|
|
357
371
|
// messages shown inside form, no navigation
|
|
358
|
-
const
|
|
372
|
+
const msg = form.toggleMessages(res.status);
|
|
373
|
+
if (msg) msg.fuse({}, scope);
|
|
359
374
|
const ok = res.status >= 200 && res.status < 300;
|
|
360
375
|
let redirect = form.getRedirect(res.status);
|
|
361
376
|
|
|
362
377
|
if (ok) {
|
|
363
378
|
form.forget();
|
|
364
379
|
form.save();
|
|
365
|
-
if (!redirect && form.closest('element-template') && !
|
|
380
|
+
if (!redirect && form.closest('element-template') && !msg) {
|
|
366
381
|
redirect = state.toString();
|
|
367
382
|
}
|
|
368
383
|
}
|