Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3: Ion-select unselect selected option

I have a simple ion-select in my template. It is not a mandatory field hence not selecting any option is allowed.

<ion-item>
  <ion-label>Gender</ion-label>
  <ion-select [(ngModel)]="gender" placeholder ="- Any -">
    <ion-option value="f">Female</ion-option>
    <ion-option value="m">Male</ion-option>
  </ion-select>
</ion-item>

I have placed a placeholder="any" and works just fine until user doesn't select anything. However, once user chooses one of the option and decides not to choose any again, user cannot go back to choosing none. I looked at the docs but couldn't get any clue. Any idea on how can user unselect the option once one of the option has been touched/chosen before?

like image 486
ro ko Avatar asked Aug 09 '17 14:08

ro ko


People also ask

What is the use of ion select option?

ion-select Selects are form controls to select an option, or options, from a set of options, similar to a native <select> element. A select should be used with child <ion-select-option> elements. If value is set on the <ion-select>, the selected option will be chosen based on that value.

How to create a check/uncheck all list in ionic using indeterminate state?

The checkMaster method will check/uncheck list items by iterating using forEach. The checkEvent will be available on every child list checkbox to calculate total checked items to handle the state of master checkbox. So using the above method we can easily create a nice check/uncheck all list in Ionic using new Indeterminate state.

How to add superhero checkbox in ionic app with angular?

Add the ion-checkbox Ionic component to configure the checkbox in an Ionic app. On the parent checkbox input field include indeterminate property to enable indeterminate state. It works on the boolean pattern and also don’t forgot to bind click event with ngModel. Attach Angular’s *ngFor directive to iterate a superheroes list.

How to use checkcheckbox in ionic 5?

The checkCheckbox () uses the forEach method to select and unselect all elements. The verifyEvent () method is counting total checked items and managing the main checkbox state. Finally, we have completed the Ionic 5 checkbox tutorial.


1 Answers

Easiest way is to add a third option of any or whatever you would like it to be

<ion-item>
  <ion-label>Gender</ion-label>
  <ion-select [(ngModel)]="gender" placeholder ="- Any -">
    <ion-option value="f">Female</ion-option>
    <ion-option value="m">Male</ion-option>
    <ion-option value="">- Any -</ion-options>
  </ion-select>
</ion-item>
like image 162
Skrettinga Avatar answered Sep 17 '22 10:09

Skrettinga