Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make the $mdDialog.prompt()'s field to be required

Here's their demo script. How do I require that the field be required?

var confirm = $mdDialog.prompt()
  .title('What would you name your dog?')
  .textContent('Bowser is a common name.')
  .placeholder('Dog name')
  .ariaLabel('Dog name')
  .initialValue('Buddy')
  .targetEvent(ev)
  .ok('Okay!')
  .cancel('I\'m a cat person');

$mdDialog.show(confirm).then(function(result) {
  $scope.status = 'You decided to name your dog ' + result + '.';
}, function() {
  $scope.status = 'You didn\'t name your dog.';
});

Currently, you can enter an empty field and then confirm the prompt, causing the dialog to close and the success function to be provoked with an undefined result value

Ideally, I'd like an error message to appear and the dialog to remain open when an empty field exists.

I'm sure I can achieve this with a custom dialog, but was hoping there was an easy setting that I'm missing

like image 786
kane Avatar asked Sep 12 '16 05:09

kane


1 Answers

I ran across this and as of Angular Material 1.1.5 there is a new required option in the prompt chain that addresses this. The reference docs haven't been updated yet, but the demos show the usage:

var confirm = $mdDialog.prompt()
  .title('What would you name your dog?')
  .textContent('Bowser is a common name.')
  .placeholder('Dog name')
  .ariaLabel('Dog name')
  .initialValue('Buddy')
  .targetEvent(ev)
  .required(true) // <---- New required option
  .ok('Okay!')
  .cancel('I\'m a cat person');
like image 88
Sherwin F Avatar answered Oct 22 '22 13:10

Sherwin F