Skip to content

Commit cfc83ad

Browse files
committed
Text inputs: Added docs for the clear-btn and clear-btn-text options
1 parent 4049ae5 commit cfc83ad

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

docs/api/data-attributes.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ <h2><a href="../forms/slider/">Slider</a></h2>
643643
<h2><a href="../forms/textinputs/">Text input &amp; Textarea</a></h2>
644644
<p>Input <code>type="text|number|search|etc."</code> or <code>textarea</code> elements are auto-enhanced, no <code>data-role</code> required</p>
645645
<table>
646+
<tr>
647+
<th>data-clear-btn</th>
648+
<td>true | <strong>false</strong> - Adds a clear button</td>
649+
</tr>
650+
<tr>
651+
<th>data-clear-btn-text</th>
652+
<td>"clear text"</strong> - Text for the clear button</td>
653+
</tr>
646654
<tr>
647655
<th>data-mini</th>
648656
<td>true | <strong>false</strong> - Compact sized version</td>

docs/forms/textinputs/index.html

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ <h2>Mini version</h2>
6363
<label for="mini">Text Input:</label>
6464
<input type="text" name="name" id="mini" value="" data-mini="true" />
6565

66+
67+
68+
<h2>Clear button option</h2>
69+
70+
<p>To add a clear button to any input (like the search input), add the <code>data-clear-btn="true"</code> attribute. The text for this clear button can be customized via the <code>data-clear-btn-text="clear input"</code> attribute. Search buttons have the clear button by default but can be controlled by this option. Note that this is available for all the input types below except for <code>textareas</code>.</p>
71+
72+
<pre><code>
73+
&lt;label for=&quot;clear-demo&quot;&gt;Text Input:&lt;/label&gt;
74+
&lt;input type=&quot;text&quot; name=&quot;clear&quot; id=&quot;clear-demo&quot; value=&quot;&quot; <strong>data-clear-btn=&quot;true&quot;</strong> /&gt;
75+
</code></pre>
76+
77+
<p>This will produce an input that is not as tall as the standard version and has a smaller text size.</p>
78+
<label for="clear-demo">Text Input:</label>
79+
<input type="text" name="clear-demo" id="clear-demo" value="" data-clear-btn="true" />
80+
6681
<h2>Field containers</h2>
6782

6883
<p>Optionally wrap the text input in a container with the <code> data-role="fieldcontain"</code> attribute to help visually group it in a longer form.</p>
@@ -86,69 +101,71 @@ <h2>More text input types</h2>
86101

87102
<p>One major advantage of using these more specific input types if that on mobile devices, specialized keyboards or pickers that speed data entry are offered in place of the standard text keyboard. Support for each input type will vary greatly across platforms, but these generally fall back to a basic text input if not understood.</p>
88103

104+
<p>Each of these inputs has the optional clear button, but browsers may not show the buttons in certain types.</p>
105+
89106
<div data-role="fieldcontain">
90107
<label for="password">Password:</label>
91-
<input type="password" name="password" id="password" value="" />
108+
<input type="password" name="password" id="password" value="" data-clear-btn="true" />
92109
</div>
93110

94111
<div data-role="fieldcontain">
95112
<label for="number">Number:</label>
96-
<input type="number" name="number" id="number" value="" />
113+
<input type="number" name="number" id="number" value="" data-clear-btn="true" />
97114
</div>
98115

99116
<div data-role="fieldcontain">
100117
<label for="number-pattern">Number + pattern:</label>
101-
<input type="number" name="number" pattern="[0-9]*" id="number-pattern" value="" placeholder="Pattern attribute [0-9]* for a numeric keypad" />
118+
<input type="number" name="number" pattern="[0-9]*" id="number-pattern" value="" data-clear-btn="true" placeholder="Pattern attribute [0-9]* for a numeric keypad" />
102119
</div>
103120

104121
<div data-role="fieldcontain">
105122
<label for="email">Email:</label>
106-
<input type="email" name="email" id="email" value="" />
123+
<input type="email" name="email" id="email" data-clear-btn="true" value="" />
107124
</div>
108125

109126
<div data-role="fieldcontain">
110127
<label for="url">Url:</label>
111-
<input type="url" name="url" id="url" value="" />
128+
<input type="url" name="url" id="url" value="" data-clear-btn="true" />
112129
</div>
113130

114131
<div data-role="fieldcontain">
115132
<label for="tel">Tel:</label>
116-
<input type="tel" name="tel" id="tel" value="" />
133+
<input type="tel" name="tel" id="tel" value="" data-clear-btn="true" />
117134
</div>
118135

119136
<div data-role="fieldcontain">
120137
<label for="time">Time:</label>
121-
<input type="time" name="time" id="time" value="" />
138+
<input type="time" name="time" id="time" value="" data-clear-btn="true" />
122139
</div>
123140

124141
<div data-role="fieldcontain">
125142
<label for="date">Date:</label>
126-
<input type="date" name="date" id="date" value="" />
143+
<input type="date" name="date" id="date" value="" data-clear-btn="true" />
127144
</div>
128145

129146
<div data-role="fieldcontain">
130147
<label for="month">Month:</label>
131-
<input type="month" name="month" id="month" value="" />
148+
<input type="month" name="month" id="month" value="" data-clear-btn="true" />
132149
</div>
133150

134151
<div data-role="fieldcontain">
135152
<label for="week">Week:</label>
136-
<input type="week" name="week" id="week" value="" />
153+
<input type="week" name="week" id="week" value="" data-clear-btn="true" />
137154
</div>
138155

139156
<div data-role="fieldcontain">
140157
<label for="datetime">Datetime:</label>
141-
<input type="datetime" name="datetime" id="datetime" value="" />
158+
<input type="datetime" name="datetime" id="datetime" data-clear-btn="true" value="" />
142159
</div>
143160

144161
<div data-role="fieldcontain">
145162
<label for="datetime-l">Datetime local:</label>
146-
<input type="datetime-local" name="datetime-l" id="datetime-l" value="" />
163+
<input type="datetime-local" name="datetime-l" id="datetime-l" value="" data-clear-btn="true" />
147164
</div>
148165

149166
<div data-role="fieldcontain">
150167
<label for="color">Color:</label>
151-
<input type="color" name="color" id="color" value="" />
168+
<input type="color" name="color" id="color" value="" data-clear-btn="true" />
152169
</div>
153170

154171

@@ -158,7 +175,7 @@ <h2>File inputs</h2>
158175

159176
<div data-role="fieldcontain">
160177
<label for="file">File:</label>
161-
<input type="file" name="file" id="file" value="" />
178+
<input type="file" name="file" id="file" value="" data-clear-btn="true" />
162179
</div>
163180

164181

docs/forms/textinputs/options.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ <h2>Text inputs</h2>
3838
<p>The text input plugin has the following options:</p>
3939

4040
<dl>
41+
<dt><code>clearBtn</code> <em>boolean</em></dt>
42+
<dd>
43+
<p class="default">default: false</p>
44+
<p>Adds a clear button to the input (not available for textareas). This option is also exposed as a data attribute: <code>data-clear-btn=&quot;true&quot;</code></p>
45+
<pre><code>$('.selector').textinput(<strong>{ clearBtn: true }</strong>);</code></pre>
46+
</dd>
47+
48+
<dt><code>clearBtnText</code> <em>string</em></dt>
49+
<dd>
50+
<p class="default">default: "clear text"</p>
51+
<p>The text description for the optional clear button, useful for assistive technologies like screen readers. This option is also exposed as a data attribute: <code>data-clear-btn-text=&quot;Clear input&quot;</code></p>
52+
<pre><code>$('.selector').textinput(<strong>{ clearBtnText: "Clear value" }</strong>);</code></pre>
53+
</dd>
54+
4155
<dt><code>disabled</code> <em>boolean</em></dt>
4256
<dd>
4357
<p class="default">default: false</p>

0 commit comments

Comments
 (0)