Material: md-dialog: prompt dialogs w/ required=true submit dialog on ENTER key of input when input empty

Created on 26 Oct 2017  路  3Comments  路  Source: angular/material

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
  }
};

https://github.com/angular/material/blob/2015ae8c9098d17c6ee9dc46859d62026071eae7/src/components/dialog/dialog.js#L647

important external contributor Pull Request fixed bug

Most helpful comment

All 3 comments

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.';
    });
  };
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dona278 picture Dona278  路  3Comments

rtprakash picture rtprakash  路  3Comments

buzybee83 picture buzybee83  路  3Comments

chriseyhorn picture chriseyhorn  路  3Comments

WebTechnolog picture WebTechnolog  路  3Comments