@ohhwells/bridge 0.1.65-next.185 → 0.1.65-next.187

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.cjs CHANGED
@@ -6914,7 +6914,7 @@ function showSuccess(form, message) {
6914
6914
  note.innerHTML = text;
6915
6915
  form.replaceChildren(note);
6916
6916
  }
6917
- function showSubmitError(form) {
6917
+ function showSubmitError(form, message = "Something went wrong. Please try again.") {
6918
6918
  let note = form.querySelector("[data-ohw-form-error]");
6919
6919
  if (!note) {
6920
6920
  note = document.createElement("p");
@@ -6923,7 +6923,7 @@ function showSubmitError(form) {
6923
6923
  note.style.marginTop = "8px";
6924
6924
  form.appendChild(note);
6925
6925
  }
6926
- note.textContent = "Something went wrong. Please try again.";
6926
+ note.textContent = message;
6927
6927
  note.style.display = "";
6928
6928
  }
6929
6929
  function clearSubmitError(form) {
@@ -6988,6 +6988,11 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6988
6988
  if (!formKey) return;
6989
6989
  e.preventDefault();
6990
6990
  clearSubmitError(form);
6991
+ const filled = collectFormFields(form);
6992
+ if (!Object.values(filled).some((value) => value.trim() !== "")) {
6993
+ showSubmitError(form, "Please fill in at least one field.");
6994
+ return;
6995
+ }
6991
6996
  const submitButton = form.querySelector(
6992
6997
  'button[type="submit"], input[type="submit"], button:not([type])'
6993
6998
  );
@@ -6999,7 +7004,7 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
6999
7004
  headers: { "Content-Type": "application/json" },
7000
7005
  body: JSON.stringify({
7001
7006
  formKey,
7002
- fields: collectFormFields(form),
7007
+ fields: filled,
7003
7008
  hasLongText: formHasLongText(form)
7004
7009
  })
7005
7010
  });
@@ -7263,7 +7268,6 @@ function insertField(form, type) {
7263
7268
  const input = fieldInputOf(wrapper);
7264
7269
  if (input) {
7265
7270
  input.setAttribute("name", key);
7266
- input.setAttribute("data-ohw-key", key);
7267
7271
  input.removeAttribute("required");
7268
7272
  input.setAttribute("placeholder", defaults.placeholder);
7269
7273
  input.value = "";
@@ -7280,9 +7284,11 @@ function duplicateField(form, wrapper) {
7280
7284
  const input = fieldInputOf(copy);
7281
7285
  if (input) {
7282
7286
  input.setAttribute("name", key);
7283
- input.setAttribute("data-ohw-key", key);
7287
+ input.removeAttribute("data-ohw-key");
7284
7288
  input.value = "";
7285
7289
  }
7290
+ const label = fieldLabelOf(copy);
7291
+ if (label) label.setAttribute("data-ohw-key", `${key}-label`);
7286
7292
  wrapper.after(copy);
7287
7293
  return copy;
7288
7294
  }
@@ -7325,8 +7331,8 @@ function reconcileFieldsFromContent(form, content) {
7325
7331
  const input = fieldInputOf(wrapper);
7326
7332
  if (input) {
7327
7333
  input.setAttribute("name", spec.key);
7328
- input.setAttribute("data-ohw-key", spec.key);
7329
7334
  }
7335
+ fieldLabelOf(wrapper)?.setAttribute("data-ohw-key", `${spec.key}-label`);
7330
7336
  byKey.set(spec.key, wrapper);
7331
7337
  }
7332
7338
  applyFieldType(wrapper, spec.type);