Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Conversation

eknowles
Copy link
Contributor

@eknowles eknowles commented Nov 20, 2017

When using the required method in $mdDialog.prompt() the user is able to hide the dialog by hitting the ENTER 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.

  • Adds missing documentation for required method.
  • Adds missing test for required method.

Fixes #10953

codepen with issue reproducible https://codepen.io/eknowles/pen/JOpgrq

…nd empty

* Adds missing documentation for `required` method.
* Adds missing test for `required` method.

Fixes 10953
@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@googlebot googlebot added the cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ label Nov 20, 2017
@eknowles
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ and removed cla: no PR author needs to sign Google's CLA: https://opensource.google.com/docs/cla/ labels Nov 20, 2017
@eknowles
Copy link
Contributor Author

I'd be happy to add a demo to the documentation for this if anyone thinks it would benefit

@Splaktar
Copy link
Contributor

@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.

@Splaktar Splaktar requested a review from mgol November 21, 2017 07:17
@Splaktar Splaktar added this to the 1.2.0 milestone Nov 21, 2017
@Splaktar Splaktar added needs: review This PR is waiting on review from the team P3: important Important issues that really should be fixed when possible. labels Nov 21, 2017
@Splaktar Splaktar modified the milestones: 1.2.0, 1.1.6 Nov 21, 2017
@Splaktar
Copy link
Contributor

@eknowles as mentioned in #10953 (comment), a CodePen isn't needed as the Dialog demos in the docs demonstrate this issue clearly.

@angular angular deleted a comment from googlebot Nov 21, 2017
@angular angular deleted a comment from googlebot Nov 21, 2017
@eknowles
Copy link
Contributor Author

No worries, if needs be, I've got a codepen here showing it https://codepen.io/eknowles/pen/JOpgrq

@Splaktar Splaktar modified the milestones: 1.1.6, 1.1.7 Jan 17, 2018
@Splaktar Splaktar self-assigned this Jan 26, 2018
Copy link
Contributor

@Splaktar Splaktar left a 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!

@@ -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) {
Copy link
Contributor

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.

@@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

@Splaktar Splaktar added in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs type: bug ux: integration and removed needs: review This PR is waiting on review from the team labels Jan 26, 2018
@Splaktar Splaktar modified the milestones: 1.1.7, 1.1.8 Feb 7, 2018
@eknowles
Copy link
Contributor Author

eknowles commented Feb 9, 2018

@Splaktar I've added that missing test case and fix the value check change, sorry for the delay!

Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review pr: lgtm This PR has been approved by the reviewer and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs labels Feb 11, 2018
@andrewseguin andrewseguin merged commit 69470a6 into angular:master Feb 16, 2018
jonbcard pushed a commit to jonbcard/material that referenced this pull request Feb 22, 2018
…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
chmelevskij pushed a commit to chmelevskij/material that referenced this pull request Jun 19, 2018
…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
Splaktar pushed a commit that referenced this pull request Jul 31, 2018
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has signed Google's CLA: https://opensource.google.com/docs/cla/ P3: important Important issues that really should be fixed when possible. pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review type: bug ux: integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants