Skip to content
This repository
Browse code

Issue 3873: Adding option for clear search button text

  • Loading branch information...
commit 2ad16962caf43a9935b9bd49481426145b3e4040 1 parent 1203f5f
Brandon Johnson authored March 21, 2012
3  docs/forms/search/index.html
@@ -86,7 +86,8 @@
86 86
 	         <input type="search" name="search3" id="searchA" value="" data-theme="a" />
87 87
 			</div>
88 88
 
89  
-		
  89
+			<h2>Setting the clear button text</h2>
  90
+			<p>The text for the button used to clear the search input of text can be configured for all search inputs by binding to the <code>mobileinit</code> event and setting the <code>$.mobile.textinput.prototype.options.clearSearchButtonText</code> property to a string of your choosing.</p>
90 91
 			
91 92
 			<h2>Calling the textinput plugin</h2>
92 93
 
9  docs/forms/search/options.html
@@ -60,7 +60,14 @@
60 60
 				<pre><code>$('.selector').textinput(<strong>{ theme: "a" }</strong>);</code></pre>
61 61
 			</dd>
62 62
 			
63  
-		</dl>	
  63
+			<dt><code>clearSearchButtonText</code> <em>string</em></dt>
  64
+			<dd>
  65
+				<p class="default">default: "clear text"</p>
  66
+				<p>Sets the text used for the button that clears the search input of text.</p>
  67
+				<pre><code>$('.selector').textinput(<strong>{ clearSearchButtonText: "custom value" }</strong>);</code></pre>
  68
+			</dd>
  69
+			
  70
+		</dl>
64 71
     
65 72
 	</form>
66 73
 	</div><!--/content-primary -->		
5  js/jquery.mobile.forms.textinput.js
@@ -13,7 +13,8 @@ $.widget( "mobile.textinput", $.mobile.widget, {
13 13
 		theme: null,
14 14
 		// This option defaults to true on iOS devices.
15 15
 		preventFocusZoom: /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1,
16  
-		initSelector: "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea, input[type='time'], input[type='date'], input[type='month'], input[type='week'], input[type='datetime'], input[type='datetime-local'], input[type='color'], input:not([type])"
  16
+		initSelector: "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea, input[type='time'], input[type='date'], input[type='month'], input[type='week'], input[type='datetime'], input[type='datetime-local'], input[type='color'], input:not([type])",
  17
+		clearSearchButtonText: "clear text"
17 18
 	},
18 19
 
19 20
 	_create: function() {
@@ -49,7 +50,7 @@ $.widget( "mobile.textinput", $.mobile.widget, {
49 50
 		if ( input.is( "[type='search'],:jqmData(type='search')" ) ) {
50 51
 
51 52
 			focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield" + themeclass + miniclass + "'></div>" ).parent();
52  
-			clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
  53
+			clearbtn = $( "<a href='#' class='ui-input-clear' title='" + o.clearSearchButtonText + "'>" + o.clearSearchButtonText + "</a>" )
53 54
 				.bind('click', function( event ) {
54 55
 					input
55 56
 						.val( "" )
2  tests/unit/textinput/index.html
@@ -56,6 +56,8 @@ <h2 id="qunit-userAgent"></h2>
56 56
   <textarea id="keyup-autogrow">
57 57
   </textarea>
58 58
   <a href="external.html" id="external">external</a>
  59
+  
  60
+  <input type="search" id="search-input">
59 61
 </div>
60 62
 </body>
61 63
 </html>
6  tests/unit/textinput/textinput_core.js
@@ -58,4 +58,10 @@
58 58
 			}
59 59
 		]);
60 60
 	});
  61
+	
  62
+	$.mobile.textinput.prototype.options.clearSearchButtonText = "custom value";
  63
+	
  64
+	test( "\"clear text\" button for search inputs should use configured text", function(){
  65
+		strictEqual( $( "#search-input" ).closest( ".ui-input-search" ).find( ".ui-input-clear" ).attr( "title" ), "custom value" );
  66
+	});
61 67
 })(jQuery);

0 notes on commit 2ad1696

Please sign in to comment.
Something went wrong with that request. Please try again.