@optionfactory/ful 6.0.1 → 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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { registry, ParsedElement, Attributes, Fragments, Nodes, Rendering } from '@optionfactory/ftl';
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
- async submit() {
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.values;
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 } });