@functionalcms/svelte-components 5.8.3 → 5.8.5

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.
@@ -11,7 +11,7 @@
11
11
  type ButtonConfig,
12
12
  type HiddenField,
13
13
  type DatePickerField,
14
- SubmitResult,
14
+ SubmitResult
15
15
  } from './form.js';
16
16
  import {
17
17
  Button,
@@ -58,11 +58,22 @@
58
58
  let isSendingMessage = $state(false);
59
59
  let loading = $state(false);
60
60
 
61
+ const isValid = (event: Event) => {
62
+ const button = event.target as HTMLButtonElement;
63
+ const form = button.closest('form') as HTMLFormElement;
64
+ const formData = new FormData(form);
65
+
66
+ const allValid = Array.from(formData.entries()).every(([, value]) => {
67
+ return value && value.toString().trim() !== '';
68
+ });
69
+ return allValid;
70
+ };
71
+
61
72
  const handleSubmit = async (event: Event) => {
62
73
  event.preventDefault();
63
74
  loading = true;
64
75
  try {
65
- if (!isSendingMessage) {
76
+ if (isValid(event) && !isSendingMessage) {
66
77
  isSendingMessage = true;
67
78
  const formData = new FormData(form);
68
79
  const response = await fetch(action, {
@@ -144,7 +155,7 @@
144
155
  required={field.required}
145
156
  disabled={field.disabled}
146
157
  class={field.class}
147
- items={field.options.map(option => ({ name: option.label, value: option.value }))}
158
+ items={field.options.map((option) => ({ name: option.label, value: option.value }))}
148
159
  bind:value={field.value}
149
160
  />
150
161
  {:else}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "5.8.3",
3
+ "version": "5.8.5",
4
4
  "license": "MIT",
5
5
  "watch": {
6
6
  "build": {