@usefillo/dom 0.5.0 → 0.5.1

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,10 @@ 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
+ if (visible.length === 0) return false;
891
+ if (visible.length > 1) return true;
892
+ return !isAutoSubmitBlock(visible[0]);
890
893
  }
891
894
  function defaultFieldRenderer(context) {
892
895
  if (context.field.kind === "hidden") return null;
@@ -911,7 +914,11 @@ function shouldAutoSubmit(field, value, api, uploading) {
911
914
  return false;
912
915
  }
913
916
  })();
914
- return hasDiscreteAnswer && validateResponse(api.form, { ...api.data, [field.id]: value }).ok;
917
+ if (!hasDiscreteAnswer) return false;
918
+ const nextData = { ...api.data, [field.id]: value };
919
+ const visible = visibleFields(api.form, nextData);
920
+ if (visible.length !== 1 || visible[0]?.id !== field.id) return false;
921
+ return validateResponse(api.form, nextData).ok;
915
922
  }
916
923
  var DomFormController = class {
917
924
  constructor(target, options) {
@@ -1212,7 +1219,7 @@ var DomFormController = class {
1212
1219
  });
1213
1220
  form.appendChild(hp);
1214
1221
  const autoSubmit = api.form.settings.submitMode === "auto";
1215
- const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(api.blocks);
1222
+ const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(visibleFields(api.form, api.data));
1216
1223
  const showFooter = showPrimaryButton || api.pageCount > 1 && !api.isFirstPage;
1217
1224
  if (showFooter) {
1218
1225
  const footer = el("footer", { className: "fillo-footer" });