You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/store-auto-subscribe-event-.../main.svelte

30 lines
564 B

<script>
import { writable } from 'svelte/store';
export function createValidator() {
const { subscribe, set } = writable({ dirty: false, valid: false });
function action(node, binding) {
return {
update(value) {
set({ dirty: true, valid: value !== '' });
}
};
}
return [{ subscribe }, action];
}
const [validity, validate] = createValidator();
let email = null;
</script>
<input class="input"
type="text"
bind:value={email}
placeholder="Type here"
use:validate={email}
/>
Dirty: {$validity.dirty}
Valid: {$validity.valid}