I can resolve undefined by keypress Enter, it should be check if required.
this.keypress = function($event) {
if ($event.keyCode === $mdConstant.KEY_CODE.ENTER) {
$mdDialog.hide(this.result); // here
}
};
Thank you for taking the time to submit this issue. However it does not follow our required issue template.
Please add a CodePen that demonstrates this problem. This gives the team the information needed to investigate the bug or prioritize the feature.
It looks like this can be reproduced here: https://material.angularjs.org/latest/demo/dialog
It seems clear that setting required(true) here should not allow the dialog to be submitted with an empty input and undefined result.
$scope.showPrompt = function(ev) {
// Appending dialog to document.body to cover sidenav in docs app
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)
.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.';
});
};
Codepen if needed https://codepen.io/eknowles/pen/JOpgrq
Most helpful comment
Codepen if needed https://codepen.io/eknowles/pen/JOpgrq