diff --git a/resources/js/components/CharCount.vue b/resources/js/components/CharCount.vue new file mode 100644 index 00000000..63dc1b7a --- /dev/null +++ b/resources/js/components/CharCount.vue @@ -0,0 +1,45 @@ + + + diff --git a/resources/js/forms/classic/interactions/InputAction.vue b/resources/js/forms/classic/interactions/InputAction.vue index a71a6f1f..4d0b3e3e 100644 --- a/resources/js/forms/classic/interactions/InputAction.vue +++ b/resources/js/forms/classic/interactions/InputAction.vue @@ -21,9 +21,18 @@ ref="inputElement" autocomplete="off" @input="onInput" + maxlength="100" v-once /> + +
| undefined = inject("disableFocus"); let storeValue = ref( - (store.currentPayload as FormBlockInteractionPayload)?.payload + (store.currentPayload as FormBlockInteractionPayload)?.payload, ); // if we restore a value from the store, we need to format it @@ -69,6 +79,7 @@ if (props.block.type === "input-number" && storeValue.value) { } const inputElement = ref(null); +const inputText = ref(inputElement.value?.value); const stepValue = 1 / Math.pow(10, props.action.options?.decimalPlaces ?? 0); const useSymbol = ref(props.action.options?.useSymbol ?? false); @@ -145,6 +156,8 @@ const onInput = (event) => { let input: string | number | null = inputElement.value.value; + inputText.value = input; + if (input && props.block.type === "input-number") { const { output } = useFixedNumberFormatting(event, { decimalPlaces: props.action.options?.decimalPlaces ?? 0, diff --git a/resources/js/forms/classic/interactions/TextareaAction.vue b/resources/js/forms/classic/interactions/TextareaAction.vue index 14ef8da1..b3667294 100644 --- a/resources/js/forms/classic/interactions/TextareaAction.vue +++ b/resources/js/forms/classic/interactions/TextareaAction.vue @@ -16,32 +16,19 @@ v-once > - - - {{ charCount }} - / {{ action.options?.max_chars }} - +
diff --git a/resources/js/forms/classic/interactions/useInputAction.ts b/resources/js/forms/classic/interactions/useInputAction.ts index 8cb96e00..30251e11 100644 --- a/resources/js/forms/classic/interactions/useInputAction.ts +++ b/resources/js/forms/classic/interactions/useInputAction.ts @@ -12,12 +12,14 @@ export function useInputAction(block: PublicFormBlockModel) { ].includes(block.type); const validator = (input: any) => { - const emailValidator = string().required().email(); - const linkValidator = string().required().url(); - const numberValidator = number().required(); + const defaultValidator = string().max(100).required(); + const emailValidator = string().max(100).required().email(); + const linkValidator = string().max(100).required().url(); + const numberValidator = number().max(100).required(); const phoneValidator = string() .required() .min(7) + .max(100) .matches(/^[+]?(?:[0-9]+[\s-]?[0-9]+)+$/); switch (block.type) { @@ -51,8 +53,10 @@ export function useInputAction(block: PublicFormBlockModel) { }; default: return { - valid: block.is_required ? input?.payload.length > 0 : true, - message: "This field is required", + valid: + (!block.is_required && !input?.payload) || + defaultValidator.isValidSync(input?.payload), + message: "Please enter a valid short text.", }; } };