Add clear ("x") button for resetting input fields
It would be cool if Ionic had a "clear" / "x" button that could appear inside inputs. I suppose it could be implemented as an AngularJS directive.
Kind of like how jQuery Mobile has a data-clear-btn="true" attribute that can be applied to input elements:
http://demos.jquerymobile.com/1.4.0/textinput/#Text
Any plans for this?
That is cool, I'll add it to our 1.0 milestone // @bensperry
http://forum.ionicframework.com/t/ionic-search-directive/3402
@gastonbesada ionSearch is cool. But when you wrap it in < label class="item item-input" >...< /label >, the label will occupy half the space, and "X" will not show in the view.
@zwz Yes, it is a custom development made by @jgx and fits its needs. @adamdbradley mention that they will include your suggested feature in ionic 1! You can wait it or take @jgx ionsearch directive.
I've implemented this in the upcoming HN app, it could be converted in to a directive. I may suggest passing a method though rather than a simple yes/no since other things may need to be done when it's cleared, such as clearing search results.
@perrygovier I totally agree with you. Besides search, any input type may have the clear button.
Hey, you guys have the wrong JGx.
On Thu, May 22, 2014 at 12:50 AM, zwz [email protected] wrote:
@perrygovier https://github.com/perrygovier I totally agree with you. Besides search, any input type may have the clear button.
— Reply to this email directly or view it on GitHubhttps://github.com/driftyco/ionic/issues/405#issuecomment-43848331 .
- Jonathan
JGx, you can unsubscribe from the thread at the bottom.
and the input clear button is really simple to do with some css plus angular.
<input type="search"
placeholder="Filter contacts..."
ng-model="search">
<button ng-if="search.length"
class="input-button button button-icon ion-android-close"
ng-click="clearSearch()">
</button>
.button.button-icon.input-button {
position: absolute;
right: 0;
top: 5px;
color: #bbb;
}
We could definitely consider adding this sort of CSS to Ionic.
I worked ajoslin's html/css into a small reusable directive. It just clears the model, doesn't accept a function, if anyone else wants to add that.
http://codepen.io/udfalkso/pen/cdfsp
@udfalkso Nice! But when I combine your directive with the validation directive (see the example of the validation directive at http://plnkr.co/edit/4oTEYmKM5GobbXlL8mrL?p=preview), it shows the "x" button, but can not be clicked to reset the field. Meanwhile, the field is validated unexpectedly before clicking the submit button.
Moving feature requests from GH Issues to Trello. Please continue the discussion and vote for this and other issues that are important to you here: https://trello.com/c/GLmSSOk6/28-add-clear-x-button-for-resetting-input-fields
billraythree
http://wondrew.net/opcion_opcion
22.03.2015, 19:30, "billraythree" [email protected]:This is a directive that you can use to wrap an input that adds the click to clear icon, plus clear on ESC key. It's for bootstrap, but you can easily adapt for ionicons.
or
Cheers, Bill
—Reply to this email directly or .
Look at this
http://plnkr.co/edit/Dje0l1?p=preview
Here's a good discussion that relates to this: http://forum.ionicframework.com/t/cannot-tap-click-a-clear-search-icon-inside-an-input-label/4237/8
Use the same technique: Either rename the enclosing <label class="item-input-wrapper> to be a <div>, or use the "on-touch" directive instead of "ng-click".
+1
Any updates on this?
We wont be adding this to Ionic core, but it'd be a welcome addition to market.ionic.io
Thanks, @perrygovier.
@perrygovier. Why isn't the X button going to be added to ionic? I'm a noob to this cordava/ionic world and I wasted multiple days and continue to waste more time on trying to get my text field to have an x button that works when you start typing. Makes me want to switch back to native development.
@salqadri Hi Salqadri, have a look at my directive, based on @udfalkso's work: https://github.com/VinceOPS/ionic-clearable-input
@salqadri - This works for me. X button appears based on angular's ng-if directive. Input get's focus after tapping the X button thanks to ionic's on-touch directive. It also works if you use a div instead of a label tag.
<label class="item-input-wrapper">
<i class="icon ion-ios-search-strong placeholder-icon"></i>
<input type="search"
placeholder="Search"
ng-model="search.string">
<a ng-if="search.string != ''"
on-touch="search.string=''">
<i class="icon ion-ios-close placeholder-icon"></i>
</a>
</label>