Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/lib/elements/forms/inputSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
error = element.validationMessage;
};
const isNotEmpty = (value: string | number | boolean) => {
const isNotEmpty = (value: string | number | boolean | null) => {
return typeof value === 'boolean' ? true : !!value;
};
Expand All @@ -49,6 +49,24 @@
}
</script>

<!-- Hidden select for HTML5 validation -->
<select
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this doesnt seem right. The pink select input does have an input already so we shouldn't need another one.

See https://github.com/appwrite/pink/blob/next/v2/pink-sb/src/lib/input/Select.svelte

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that pink Select has an input element. However, it uses type="hidden" which doesn't participate in HTML5 constraint validation per spec - the browser skips validation for hidden inputs even with required attribute.

The original code tried to work around this by calling setCustomValidity() on an element variable, but that variable was never bound to anything.

Would you prefer I:

  1. Keep the dual-select approach (current fix)
  2. Submit a PR to pink-svelte to change the hidden input to a visually-hidden text input
  3. Remove HTML5 validation and use custom validation logic instead

What's your preference?

bind:this={element}
{required}
{disabled}
bind:value
on:invalid={handleInvalid}
tabindex="-1"
aria-hidden="true"
style="position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px;">
<option value="" disabled selected={!isNotEmpty(value)}></option>
{#each options as option}
<option value={option.value} selected={option.value === value}>
{option.label}
</option>
{/each}
</select>

<Input.Select
{id}
{label}
Expand All @@ -59,9 +77,7 @@
{autofocus}
{leadingIcon}
helper={error ?? helper}
{required}
state={error ? 'error' : 'default'}
on:invalid={handleInvalid}
on:input
on:change
bind:value>
Expand Down