-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelect.svelte
69 lines (63 loc) · 1.22 KB
/
Select.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!--
Can be used like this
<Select
bind:value={value}
{...props}>
where props = {
id,
name,
valid: null,
options: [{
id,
name,
},
...],
errorMessage,
validation = {
validate: (ev) => { after on:change },
}
}
-->
<script>
import { fade } from 'svelte/transition';
export let value;
export let id;
export let name;
export let valid;
export let options = [];
export let errorMessage;
export let validation;
</script>
<label for="{id}">{name}*</label>
<select
name="{id}"
id="{id}"
bind:value={value}
on:change={validation.validate}
class:error={valid === false}
required>
<option value="" disabled selected>Choose {name}...</option>
{#each options as option}
<option value={option.id}>
{option.name}
</option>
{/each}
</select>
{#if valid === false}
<label for="{id}" class="error" transition:fade>
{@html errorMessage}
</label>
{/if}
<style>
select{
margin-bottom: 20px;
height: 40px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
padding: 10px;
}
option:disabled {
display: none;
}
</style>