@usefillo/dom 0.5.0 → 0.5.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/index.js CHANGED
@@ -19,7 +19,8 @@ import {
19
19
  provisionWorkspace,
20
20
  syncCodeForm,
21
21
  toE164,
22
- validateResponse
22
+ validateResponse,
23
+ visibleFields
23
24
  } from "@usefillo/core";
24
25
  var FIELD_INPUT_PREFIX = "fillo-";
25
26
  var domInstanceCounter = 0;
@@ -885,8 +886,11 @@ var DEFAULT_COMPONENTS = {
885
886
  function isAutoSubmitBlock(block) {
886
887
  return isField(block) && (block.kind === "select" || block.kind === "dropdown" || block.kind === "checkbox" || block.kind === "rating" || block.kind === "linear_scale");
887
888
  }
888
- function needsExplicitSubmit(blocks) {
889
- return blocks.some((block) => isField(block) && block.kind !== "hidden" && !isAutoSubmitBlock(block));
889
+ function needsExplicitSubmit(visible) {
890
+ const interactive = visible.filter((b) => !(isField(b) && b.kind === "hidden"));
891
+ if (interactive.length === 0) return false;
892
+ if (interactive.length > 1) return true;
893
+ return !isAutoSubmitBlock(interactive[0]);
890
894
  }
891
895
  function defaultFieldRenderer(context) {
892
896
  if (context.field.kind === "hidden") return null;
@@ -911,7 +915,11 @@ function shouldAutoSubmit(field, value, api, uploading) {
911
915
  return false;
912
916
  }
913
917
  })();
914
- return hasDiscreteAnswer && validateResponse(api.form, { ...api.data, [field.id]: value }).ok;
918
+ if (!hasDiscreteAnswer) return false;
919
+ const nextData = { ...api.data, [field.id]: value };
920
+ const interactive = visibleFields(api.form, nextData).filter((f) => f.kind !== "hidden");
921
+ if (interactive.length !== 1 || interactive[0]?.id !== field.id) return false;
922
+ return validateResponse(api.form, nextData).ok;
915
923
  }
916
924
  var DomFormController = class {
917
925
  constructor(target, options) {
@@ -1212,7 +1220,7 @@ var DomFormController = class {
1212
1220
  });
1213
1221
  form.appendChild(hp);
1214
1222
  const autoSubmit = api.form.settings.submitMode === "auto";
1215
- const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(api.blocks);
1223
+ const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(visibleFields(api.form, api.data));
1216
1224
  const showFooter = showPrimaryButton || api.pageCount > 1 && !api.isFirstPage;
1217
1225
  if (showFooter) {
1218
1226
  const footer = el("footer", { className: "fillo-footer" });