0

I am new to ionic and I want to be able to create a gender toggle button in my application. I don't want to use checkbox but convert the checkbox to toogle as the image below.

enter image description here

if I am to build it in html and jQuery it will be this way

<div class="checkbox">
      <input type="checkbox" name="gender" id="gender" checked />
     </div>
    </div>
    <input type="hidden" name="hidden_gender" id="hidden_gender" value="Male" />

In jQuery

 $('#gender').bootstrapToggle({
  on: 'Male',
  off: 'Female',
  onstyle: 'success',
  offstyle: 'danger'
 });

 $('#gender').change(function(){
  if($(this).prop('checked'))
  {
   $('#hidden_gender').val('Male');
  }
  else
  {
   $('#hidden_gender').val('Female');
  }
 });

Thanks.

Tonye Boro
  • 313
  • 4
  • 15

1 Answers1

0

I think what you're looking for is <ion-toggle/>.

For documentation on this component, see: https://ionicframework.com/docs/components/#toggle

Here's a copy/paste of a line from how I'm using the tag in an Angular application:

<ion-toggle [(ngModel)]="track.isChecked" color="secondary"></ion-toggle>