-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(dialog): fix prompt closing on ENTER key when input is required and empty #10990
fix(dialog): fix prompt closing on ENTER key when input is required and empty #10990
Conversation
…nd empty * Adds missing documentation for `required` method. * Adds missing test for `required` method. Fixes 10953
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
I'd be happy to add a demo to the documentation for this if anyone thinks it would benefit |
@eknowles a simple CodePen to show the problematic behavior would be a good first step since the original issue did not include that. Thank you very much for your contribution. |
@eknowles as mentioned in #10953 (comment), a CodePen isn't needed as the Dialog demos in the docs demonstrate this issue clearly. |
No worries, if needs be, I've got a codepen here showing it https://codepen.io/eknowles/pen/JOpgrq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good start. I think that it just needs one minor change and one more test. Thank you!
src/components/dialog/dialog.spec.js
Outdated
@@ -781,6 +781,34 @@ describe('$mdDialog', function() { | |||
|
|||
expect(response).toBe('responsetext'); | |||
})); | |||
|
|||
it('should not submit after ENTER key when input is empty and prompt is required', inject(function($mdDialog, $rootScope, $timeout, $mdConstant) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but I think that we should also have a test that: when required is set and the input has a value that hide is called and the result is correct.
src/components/dialog/dialog.js
Outdated
@@ -658,7 +659,9 @@ function MdDialogProvider($$interimElementProvider) { | |||
$mdDialog.cancel(); | |||
}; | |||
this.keypress = function($event) { | |||
if ($event.keyCode === $mdConstant.KEY_CODE.ENTER) { | |||
var invalidPrompt = isPrompt && this.required && !this.result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this check is accurate enough. The input could be asking for the number of children and 0 would be a valid response. However !this.result
would be false and flag the result as invalid in that case. angular.isDefined(this.result)
is a safer approach and is used in many other components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
@Splaktar I've added that missing test case and fix the value check change, sorry for the delay! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…nd empty (angular#10990) * fix(dialog): fix prompt closing on ENTER key when input is required and empty * Adds missing documentation for `required` method. * Adds missing test for `required` method. Fixes 10953 * fix(dialog): fix issue where prompt value of 0 would pass required check * test(dialog): check prompt should call hide when is required and has value
…nd empty (angular#10990) * fix(dialog): fix prompt closing on ENTER key when input is required and empty * Adds missing documentation for `required` method. * Adds missing test for `required` method. Fixes 10953 * fix(dialog): fix issue where prompt value of 0 would pass required check * test(dialog): check prompt should call hide when is required and has value
…nd empty (#10990) * fix(dialog): fix prompt closing on ENTER key when input is required and empty * Adds missing documentation for `required` method. * Adds missing test for `required` method. Fixes 10953 * fix(dialog): fix issue where prompt value of 0 would pass required check * test(dialog): check prompt should call hide when is required and has value
When using the
required
method in$mdDialog.prompt()
the user is able to hide the dialog by hitting theENTER
key even when the input is empty, defeating the implication of a required input. This PR adds a check on keypress to ensure if the dialog is prompt and is required that a value is present.required
method.required
method.Fixes #10953
codepen with issue reproducible https://codepen.io/eknowles/pen/JOpgrq