forked from OnsenUI/playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.html
More file actions
171 lines (138 loc) · 5.11 KB
/
Copy pathinput.html
File metadata and controls
171 lines (138 loc) · 5.11 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Onsen UI App</title>
<script>
ons.bootstrap()
.controller('PageController', function() {
this.username = '';
this.password = '';
this.login = function() {
if (this.username === 'bob' && this.password === 'secret') {
ons.notification.alert('Congratulations!');
}
else {
ons.notification.alert('Incorrect username or password.');
}
};
this.apples = true;
this.bananas = false;
this.labelStyle = {
marginLeft: '6px',
width: '10px',
height: '10px',
borderRadius: '100%',
backgroundColor: 'transparent',
display: 'inline-block'
};
});
</script>
</head>
<body>
<ons-page ng-controller="PageController as page" >
<ons-toolbar>
<div class="center">Input</div>
</ons-toolbar>
<p style="text-align: center; margin-top: 10px">
<ons-search-input placeholder="Search"></ons-search-input>
</p>
<div style="text-align: center; margin-top: 30px">
<p>
<ons-input id="username" modifier="underbar" placeholder="Username" float ng-model="page.username"></ons-input>
</p>
<p>
<ons-input id="password" modifier="underbar" type="password" placeholder="Password" float ng-model="page.password"></ons-input>
</p>
<p style="margin-top: 30px;">
<ons-button ng-click="page.login()">Sign in</ons-button>
</p>
</div>
<ons-list>
<ons-list-header>Checkboxes</ons-list-header>
<ons-list-item tappable>
<label class="left">
<ons-checkbox input-id="check-1" ng-model="page.apples"></ons-checkbox>
</label>
<label for="check-1" class="center">
Apples <span ng-show="page.apples" style="color: red; margin-left: 6px">♥</span>
</label>
</ons-list-item>
<ons-list-item tappable>
<label class="left">
<ons-checkbox input-id="check-2" ng-model="page.bananas"></ons-checkbox>
</label>
<label for="check-2" class="center">
Bananas <span ng-show="page.bananas" style="color: red; margin-left: 6px">♥</span>
</label>
</ons-list-item>
</ons-list>
<ons-list>
<ons-list-header>Radio buttons <span ng-style="page.labelStyle"></span></ons-list-header>
<ons-list-item tappable>
<label class="left">
<ons-radio name="color" input-id="radio-1" ng-model="page.labelStyle.backgroundColor" value="red"></ons-radio>
</label>
<label for="radio-1" class="center">
Red
</label>
</ons-list-item>
<ons-list-item tappable>
<label class="left">
<ons-radio name="color" input-id="radio-2" ng-model="page.labelStyle.backgroundColor" value="blue"></ons-radio>
</label>
<label for="radio-2" class="center">
Blue
</label>
</ons-list-item>
</ons-list>
</ons-page>
</body>
</html>
<!-- info
## Form inputs
In Onsen UI text input is provided by the `<ons-input>` tag. It works exactly like the normal `<input>` tag but with some small differences.
Just like the normal input tag you can use the `type` attribute to define what kind of input that should be displayed. To get an number input you can use the `number` type:
```
<ons-input
type="number"
placeholder="Age"
min="0"
max="200">
</ons-input>
```
You can also use types like `number` or `date`. The only exception are checkboxes and radio buttons, which are implemented in different elements.
## Floating label
For Android devices the input will displayed as a Material Design input element. One of the features of this input is that it can have a floating label which will animated when the user starts typing. Try changing the style to Android to see how it works.
The label is defined with the `placeholder` attribute and to activate the animation the `float` attribute is required.
```
<ons-input
placeholder="Username"
float>
</ons-input>
```
## Checkboxes
Checkboxes are defined using the `<ons-checkbox>` element. The element works almost exactly as when you use a normal `<input type="checkbox">` element.
```
<ons-checkbox value="something" checked></ons-checkbox>
```
## Radio buttons
Radio buttons are defined using the `<ons-radio>` element.
```
<ons-radio checked></ons-radio>
```
To create a group of radio buttons the `name` attribute is used:
```
<ons-radio name="group" value="first"></ons-radio>
<ons-radio name="group" value="second"></ons-radio>
```
This will enable switching between radio buttons.
## Inner input element
For normal input elements is possible to define a `<label>` tab with the `for` attribute to link it to an input element.
Unfortunately this does not work with custom elements like `<ons-label>` so in order to do it we need to set the `id` attribute of the inner input element. This is done using the `input-id` attribute.
```
<label for="username">Username</label>
<ons-input input-id="username"></ons-input>
```
This work with any input in Onsen UI such as checkboxes, radios, etc.
-->