diff --git a/src/lib/elements/forms/inputText.svelte b/src/lib/elements/forms/inputText.svelte index 2c69fa8e4..8ca3ef587 100644 --- a/src/lib/elements/forms/inputText.svelte +++ b/src/lib/elements/forms/inputText.svelte @@ -11,6 +11,8 @@ export let id: string; export let name: string = id; export let value = ''; + export let pattern: string = null; + export let patternError: string = ''; export let placeholder = ''; export let required = false; export let hideRequired = false; @@ -45,6 +47,11 @@ return; } + if (patternError && element.validity.patternMismatch) { + error = patternError; + return; + } + error = element.validationMessage; }; @@ -118,6 +125,7 @@ {disabled} {readonly} {required} + {pattern} {maxlength} autocomplete={autocomplete ? 'on' : 'off'} type="text" diff --git a/src/lib/helpers/string.ts b/src/lib/helpers/string.ts index ecf5c03aa..e28a98f2d 100644 --- a/src/lib/helpers/string.ts +++ b/src/lib/helpers/string.ts @@ -50,19 +50,6 @@ export function formatNum(number: number): string { } /** - * Validates a hostname, optionally allowing wildcards. - * - * @param {string} hostname - The hostname to validate. - * @param {boolean} [wildcard=true] - Whether to allow wildcard hostnames (e.g., `*.example.com`). + * Returns a regex to check hostname validity. Supports wildcards too! */ -export function isHostnameValid(hostname: string, wildcard: boolean = true): boolean { - if (!hostname) return false; - - if (!wildcard && hostname.startsWith('*.')) return false; - - const hostnameRegex = wildcard - ? /^(\*\.)?([a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/ - : /^([a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/; - - return hostnameRegex.test(hostname); -} +export const hostnameRegex = String.raw`(\*)|(\*\.)?(?!-)[A-Za-z0-9\-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,18}`; diff --git a/src/lib/layout/wizard.svelte b/src/lib/layout/wizard.svelte index 4a27583c5..95f462c07 100644 --- a/src/lib/layout/wizard.svelte +++ b/src/lib/layout/wizard.svelte @@ -68,12 +68,10 @@ } async function submit() { - let interceptorResponse = null; - if ($wizard.interceptor) { $wizard.nextDisabled = true; try { - interceptorResponse = await $wizard.interceptor(); + await $wizard.interceptor(); } catch (error) { if (!$wizard.interceptorNotificationEnabled) return; addNotification({ @@ -86,10 +84,6 @@ } } - // maintains backward compatibility. - // explicit boolean check as the return type can be undefined/void too! - if (typeof interceptorResponse === 'boolean' && interceptorResponse === false) return; - wizard.setInterceptor(null); if (isLastStep) { if ($wizard.finalAction) { diff --git a/src/lib/layout/wizardStep.svelte b/src/lib/layout/wizardStep.svelte index ffbd91945..cddb57463 100644 --- a/src/lib/layout/wizardStep.svelte +++ b/src/lib/layout/wizardStep.svelte @@ -4,14 +4,9 @@ import { onDestroy } from 'svelte'; /** - * Pass callback that is run before the Form submit, - * can be canceled by throwing an `Exception` or returning `false`. - * - * Example - - * 1. validate > throw Error > notification is shown - * 2. validate > return False > show your UI as no notification is shown. + * Pass callback that is run before the Form submit, can be canceled with throwing an exception. */ - export let beforeSubmit: () => Promise | Promise = null; + export let beforeSubmit: () => Promise = null; export let nextDisabled = false; $: wizard.setNextDisabled(nextDisabled); diff --git a/src/lib/stores/wizard.ts b/src/lib/stores/wizard.ts index 479bd4d33..6a752584f 100644 --- a/src/lib/stores/wizard.ts +++ b/src/lib/stores/wizard.ts @@ -8,7 +8,7 @@ export type WizardStore = { media?: string; component?: typeof SvelteComponent; cover?: typeof SvelteComponent; - interceptor?: () => Promise | Promise; + interceptor?: () => Promise; finalAction?: () => Promise; nextDisabled: boolean; step: number; diff --git a/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte b/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte index 630201d50..d67c3f6d9 100644 --- a/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte +++ b/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte @@ -1,14 +1,14 @@ @@ -188,12 +174,10 @@ placeholder={placeholder[platform].hostname} tooltip={placeholder[platform].tooltip} required + pattern={hostnameRegex} + patternError="Please enter a valid hostname" bind:value={$createPlatform.hostname} /> - {#if error} - {error} - {/if} -
{#each suggestions as suggestion} @@ -73,12 +60,10 @@ placeholder="localhost" tooltip="The hostname that your website will use to interact with the Appwrite APIs in production or development environments. No protocol or port number required." required + pattern={hostnameRegex} + patternError="Please enter a valid hostname" bind:value={$createPlatform.hostname} /> - {#if error} - {error} - {/if} -
{#each suggestions as suggestion}