@pageboard/html 0.14.3 → 0.14.5
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 +1 -1
- package/package.json +1 -1
- package/ui/form.js +21 -21
- package/ui/input-file.js +14 -4
package/elements/form.js
CHANGED
|
@@ -180,7 +180,7 @@ exports.api_form = {
|
|
|
180
180
|
tag: 'form[method="post"]',
|
|
181
181
|
html: `<form is="element-form" method="post" name="[name]" masked="[masked]"
|
|
182
182
|
action="/.api/form/[$id]"
|
|
183
|
-
parameters="[$expr?.action?.parameters|
|
|
183
|
+
parameters="[$expr?.action?.parameters|as:expressions]"
|
|
184
184
|
success="[redirection.url][redirection.parameters|as:query]"
|
|
185
185
|
badrequest="[badrequest.url][badrequest.parameters|as:query]"
|
|
186
186
|
unauthorized="[unauthorized.url][unauthorized.parameters|as:query]"
|
package/package.json
CHANGED
package/ui/form.js
CHANGED
|
@@ -338,32 +338,32 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
338
338
|
}
|
|
339
339
|
async postMethod(e, state) {
|
|
340
340
|
const form = this;
|
|
341
|
-
if (e.type != "submit" && form.elements.find(item => item.type == "submit"))
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
await Promise.all(
|
|
346
|
-
Array.from(form.elements)
|
|
347
|
-
.filter(node => Boolean(node.presubmit) && !node.disabled)
|
|
348
|
-
.map(input => input.presubmit(state))
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
const request = form.read(true);
|
|
352
|
-
form.disable();
|
|
353
|
-
|
|
354
|
-
const res = await state.fetch(form.method, Page.format({
|
|
355
|
-
pathname: form.getAttribute('action'),
|
|
356
|
-
query: state.query
|
|
357
|
-
}), request).catch(err => err);
|
|
341
|
+
if (e.type != "submit" && form.elements.find(item => item.type == "submit")) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
358
344
|
|
|
359
345
|
const scope = state.scope.copy();
|
|
346
|
+
scope.$request = form.read(true);
|
|
347
|
+
try {
|
|
348
|
+
const prelist = Array.from(form.elements)
|
|
349
|
+
.filter(node => Boolean(node.presubmit) && !node.disabled);
|
|
350
|
+
form.disable();
|
|
351
|
+
for (const node of prelist) {
|
|
352
|
+
await node.presubmit(state);
|
|
353
|
+
}
|
|
354
|
+
form.classList.add('loading');
|
|
355
|
+
scope.$response = await state.fetch(form.method, Page.format({
|
|
356
|
+
pathname: form.getAttribute('action'),
|
|
357
|
+
query: state.query
|
|
358
|
+
}), scope.$request);
|
|
359
|
+
} catch (err) {
|
|
360
|
+
scope.$response = err;
|
|
361
|
+
}
|
|
362
|
+
const res = scope.$response;
|
|
360
363
|
if (res?.grants) state.scope.$grants = res.grants;
|
|
361
|
-
scope.$request = request;
|
|
362
|
-
|
|
363
|
-
scope.$response = res;
|
|
364
364
|
scope.$status = res.status;
|
|
365
|
-
form.enable();
|
|
366
365
|
|
|
366
|
+
form.enable();
|
|
367
367
|
form.classList.remove('loading');
|
|
368
368
|
|
|
369
369
|
// messages shown inside form, no navigation
|
package/ui/input-file.js
CHANGED
|
@@ -99,10 +99,20 @@ class HTMLElementInputFile extends Page.create(HTMLInputElement) {
|
|
|
99
99
|
|
|
100
100
|
xhr.addEventListener('load', () => {
|
|
101
101
|
track(100);
|
|
102
|
+
let obj;
|
|
102
103
|
try {
|
|
103
|
-
|
|
104
|
-
} catch
|
|
105
|
-
|
|
104
|
+
obj = JSON.parse(xhr.responseText);
|
|
105
|
+
} catch {
|
|
106
|
+
obj = { type: 'error', data: { message: xhr.responseText } };
|
|
107
|
+
}
|
|
108
|
+
if (obj.type == "error") {
|
|
109
|
+
obj.statusText = obj.data?.message ?? '';
|
|
110
|
+
}
|
|
111
|
+
obj.status = xhr.status;
|
|
112
|
+
if (xhr.status < 200 || xhr.status >= 400) {
|
|
113
|
+
fail(obj);
|
|
114
|
+
} else {
|
|
115
|
+
pass(obj);
|
|
106
116
|
}
|
|
107
117
|
});
|
|
108
118
|
|
|
@@ -110,7 +120,7 @@ class HTMLElementInputFile extends Page.create(HTMLInputElement) {
|
|
|
110
120
|
if (xhr.status == 0) return fail("Connection error");
|
|
111
121
|
const msg = xhr.statusText || "Connection error";
|
|
112
122
|
const err = new Error(msg);
|
|
113
|
-
err.
|
|
123
|
+
err.status = xhr.status;
|
|
114
124
|
fail(err);
|
|
115
125
|
});
|
|
116
126
|
try {
|