Ionic 2, ion-select, let user clear selection

1.4k Views Asked by At

I'm new at Ionic2 and angular2.

I use ion-select plugin. This plugin display popup with options-list by radio-buttons, and to "submit" buttons - OK and Cancel.

I want to let user see third option - "Clear Selection". Is this plugin support this feature? If not - what is the best way to do it?

1

There are 1 best solutions below

0
On

There is no way to add additional button to select popup: https://ionicframework.com/docs/v2/api/components/select/Select/ - you can just set text for buttons.

You should use AlertController for that - it allows you to create buttons. Here is a good example: https://github.com/driftyco/ionic-preview-app/blob/master/src/pages/alerts/radio/pages.ts

let alert = this.alertCtrl.create();
alert.setTitle('Lightsaber color');

alert.addInput({
  type: 'radio',
  label: 'Blue',
  value: 'blue',
  checked: true
});

alert.addInput({
  type: 'radio',
  label: 'Green',
  value: 'green'
});

alert.addButton('Cancel');
alert.addButton({
  text: 'Ok',
  handler: data => {
    console.log('Radio data:', data);
    this.testRadioOpen = false;
    this.testRadioResult = data;
  }
});

alert.present().then(() => {
  this.testRadioOpen = true;
});

Unfortunately 3rd button will damage alert UI, so you need to create some css to fix it.