@optionfactory/ful 6.0.0 → 6.0.2
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/dist/ful.iife.js +18 -6
- package/dist/ful.iife.js.map +1 -1
- package/dist/ful.iife.min.js +1 -1
- package/dist/ful.iife.min.js.map +1 -1
- package/dist/ful.min.mjs +1 -1
- package/dist/ful.min.mjs.map +1 -1
- package/dist/ful.mjs +19 -7
- package/dist/ful.mjs.map +1 -1
- package/package.json +4 -4
package/dist/ful.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParsedElement, Attributes, registry, Fragments, Nodes, Rendering } from '@optionfactory/ftl';
|
|
2
2
|
|
|
3
3
|
class Base64 {
|
|
4
4
|
static encode(arrayBuffer, dialect) {
|
|
@@ -1213,14 +1213,18 @@ class Bindings {
|
|
|
1213
1213
|
/**
|
|
1214
1214
|
*
|
|
1215
1215
|
* @param {HTMLFormElement} form
|
|
1216
|
+
* @param {HTMLElement} [submitter]
|
|
1216
1217
|
* @returns
|
|
1217
1218
|
*/
|
|
1218
|
-
static extractFrom(form){
|
|
1219
|
+
static extractFrom(form, submitter){
|
|
1219
1220
|
let result = {};
|
|
1220
1221
|
for(const el of form.elements){
|
|
1221
1222
|
if(!el.hasAttribute("name") || el.matches(":disabled")){
|
|
1222
1223
|
continue;
|
|
1223
1224
|
}
|
|
1225
|
+
if(submitter && (el.type==='submit' || el.type === 'reset') && el !== submitter){
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1224
1228
|
result = Bindings.providePath(result, /** @type {string} */(el.getAttribute('name')), Bindings.extract(el));
|
|
1225
1229
|
}
|
|
1226
1230
|
return result;
|
|
@@ -1354,7 +1358,7 @@ class Form extends ParsedElement {
|
|
|
1354
1358
|
form.addEventListener('submit', async (e) => {
|
|
1355
1359
|
e.preventDefault();
|
|
1356
1360
|
e.stopPropagation();
|
|
1357
|
-
await this.submit();
|
|
1361
|
+
await this.submit(e.submitter);
|
|
1358
1362
|
});
|
|
1359
1363
|
if (this.hasAttribute("clear-invalid-on-change")) {
|
|
1360
1364
|
this.addEventListener('change', (/** @type any */evt) => {
|
|
@@ -1363,11 +1367,16 @@ class Form extends ParsedElement {
|
|
|
1363
1367
|
}
|
|
1364
1368
|
this.replaceChildren(form);
|
|
1365
1369
|
}
|
|
1366
|
-
|
|
1370
|
+
/**
|
|
1371
|
+
*
|
|
1372
|
+
* @param {HTMLElement} [submitter]
|
|
1373
|
+
* @returns
|
|
1374
|
+
*/
|
|
1375
|
+
async submit(submitter) {
|
|
1367
1376
|
this.spinner(true);
|
|
1368
1377
|
try {
|
|
1369
1378
|
const loader = registry.component(this.getAttribute("loader") ?? 'loaders:form').create(this);
|
|
1370
|
-
const values = this.
|
|
1379
|
+
const values = Bindings.extractFrom(this.form, submitter);
|
|
1371
1380
|
let request = await loader.prepare(values, this);
|
|
1372
1381
|
try {
|
|
1373
1382
|
const se = new CustomEvent('submit', { bubbles: true, cancelable: true, detail: { values, request } });
|
|
@@ -1400,8 +1409,11 @@ class Form extends ParsedElement {
|
|
|
1400
1409
|
const hel = /** @type HTMLElement */ (el);
|
|
1401
1410
|
hel.hidden = !spin;
|
|
1402
1411
|
});
|
|
1403
|
-
this.querySelectorAll('
|
|
1404
|
-
const hel = /** @type HTMLButtonElement */ (el);
|
|
1412
|
+
this.querySelectorAll('input,button').forEach(el => {
|
|
1413
|
+
const hel = /** @type HTMLButtonElement|HTMLInputElement */ (el);
|
|
1414
|
+
if(hel.type !== 'submit' && hel.type !== 'reset'){
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1405
1417
|
hel.disabled = spin;
|
|
1406
1418
|
});
|
|
1407
1419
|
}
|