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
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With