Popup prompt how to know 'OK' or 'Cancel' clicked?


#1

popup confirm how to know ‘OK’ or ‘Cancel’ clicked?

$ionicPopup.prompt({
              title: 'Password Check',
              subTitle: 'Enter your secret password',
              inputType: 'password',
              inputPlaceholder: 'Your password'
   }).then(function(res) {
              console.log('Your name is', res);
});

either click the cancel or ok all trigger the then callback.


#2

The “res” is the response from closing the prompt. If res === false, the cancel was clicked. If res === 'something else', then data was entered in the field, the “Okay” button was pressed and you are returned what was typed in the field.


#3

@Calendee Thanks for your response. If the validation allow to leave the input blank, should we just use popup function not prompt function.


#4

Just return true on the tap if you want to allow it to be blank.

See : http://codepen.io/calendee/pen/BHgCz

buttons: [
  { text: 'Cancel', onTap: function(e) { return true; } },
  {
    text: '<b>Save</b>',
    type: 'button-positive',
    onTap: function(e) {
      return $scope.data.wifi || true;
    }
  },
]

#5

@Calendee Thanks for you demo, you are so nice :smiley: