radio group: fix live validation after invalid
This commit is contained in:
@@ -23,8 +23,20 @@
|
||||
...props
|
||||
}: Props = $props();
|
||||
let valid = $state(true);
|
||||
let hiddenInput: HTMLInputElement;
|
||||
|
||||
const group = new RadioGroup(props);
|
||||
const group = new RadioGroup({
|
||||
...props,
|
||||
onValueChange(active) {
|
||||
// call any passed in handler
|
||||
props.onValueChange?.(active);
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
// send keyboard event to trigger validation
|
||||
hiddenInput?.dispatchEvent(new KeyboardEvent('keyup'));
|
||||
});
|
||||
}
|
||||
});
|
||||
const isVert = $derived(group.orientation === 'vertical');
|
||||
</script>
|
||||
|
||||
@@ -69,8 +81,9 @@
|
||||
</div>
|
||||
<input
|
||||
{...group.hiddenInput}
|
||||
use:validate={{ required }}
|
||||
use:validate={{ required, autovalOnInvalid: true }}
|
||||
onvalidate={(e) => (valid = e.detail.valid)}
|
||||
bind:this={hiddenInput}
|
||||
/>
|
||||
|
||||
{#if required}
|
||||
|
||||
Reference in New Issue
Block a user