-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathselect-and-access.html
52 lines (51 loc) · 1.38 KB
/
select-and-access.html
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
---
title: Bound "select" and access selection data example
layout: example.njk
---
<div x-data="page()" class="flex flex-col">
<h3 class="text-xl font-semibold text-gray-900 mb-8">
Bound "select" and access selection data
</h3>
<div class="flex flex-col w-full md:w-2/3">
<select
x-model="selectedOption"
class="inline-block w-full appearance-none bg-white border border-gray-400 hover:border-gray-500 px-4 py-2 pr-8 rounded shadow leading-tight focus:outline-none focus:shadow-outline"
>
<option value="">Select an option</option>
<template x-for="option in options">
<option
:key="option.value"
:value="option.value"
x-text="option.text"
></option>
</template>
</select>
<button
@click="access()"
class="mt-4 w-full bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Access Data
</button>
</div>
<label class="block">Output: "<span x-ref="output"></span>"</label>
<script>
function page() {
return {
selectedOption: "",
options: [
{
value: "bacon",
text: "Bacon",
},
{
value: "ham",
text: "Ham",
},
],
access() {
this.$refs.output.innerText = this.selectedOption;
},
};
}
</script>
</div>