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

required error on md-select not prevent the submit event #8599

Closed
leibale opened this issue May 31, 2016 · 11 comments
Closed

required error on md-select not prevent the submit event #8599

leibale opened this issue May 31, 2016 · 11 comments
Milestone

Comments

@leibale
Copy link
Contributor

leibale commented May 31, 2016

i have a form with ng-submit attribute and two inputs:

  • md-input
  • md-select

both of them are required
if the md-input is empty the submit is stopped (when you click the focus is set to the required input and a message pops on top of it)
if the md-select is empty the submit doesn't recognize it and goes through.

code example

Angular Versions:

  • Angular Version: 1.5.5
  • Angular Material Version: 1.0.9
@crisbeto
Copy link
Member

crisbeto commented May 31, 2016

I believe the select works as intended. Your form doesn't submit when the text field is empty, because of the default browser required attribute, not any of Angular's validations. If you add novalidate to the form, in order to disable the native browser validation, and you comment out the select, you can see that you can still submit the form with an empty input.

Here's a fork of your Plunk: http://plnkr.co/edit/LBptzJyyIi24ZvIadVTM?p=preview. If you try to log the statusForm.status.$error, you can see that the required error is being set properly.

@leibale
Copy link
Contributor Author

leibale commented May 31, 2016

@crisbeto so i must add ng-disabled on the submit button..?
and what about required error style (red border) for md-select?

@crisbeto
Copy link
Member

You can either add ng-disabled on the button, or pass the statusForm.$valid to the submit method and prevent it from submitting there.

As for the red border, it will show up when the select is "dirty", e.g. if the user selected and then removed the value. You can see what that looks like in the "Validations" demo at the bottom.

@leibale
Copy link
Contributor Author

leibale commented May 31, 2016

@crisbeto the css rule for the error message in md-input is .ng-invalid and for md-select is .ng-invalid.ng-dirty, why there is a difference?

@crisbeto
Copy link
Member

I'm not sure really, it might have to do with UX, so an empty select doesn't get highlighted the first time the user opens the page.

@leibale
Copy link
Contributor Author

leibale commented May 31, 2016

@crisbeto sorry, the css rule for the error message in md-input is md-input-invalid not .ng-invalid. this class added only after focus or submit (and not when the page opens).
could you ask the UX team or send them a link to this issue?

@ThomasBurleson ThomasBurleson added this to the Deprecated milestone May 31, 2016
@crisbeto
Copy link
Member

I'm pretty sure that this is the intended behaviour. If you want to make it underline when the form is submitted, you can add this to your CSS:

.ng-submitted md-select.ng-invalid .md-select-value{
  color: rgb(221,44,0);
  border-bottom-color: rgb(221,44,0);
}

@leibale
Copy link
Contributor Author

leibale commented May 31, 2016

@crisbeto there is no way that this is what the UX team wants.. if you can ask them and make sure that this is the behaviour it will be great :)

for now i will use the css you gave me

@topherfangio
Copy link
Contributor

Part of this issue appears related to #8529 which I am working on today.

@leibale
Copy link
Contributor Author

leibale commented May 31, 2016

@crisbeto told you.. ;)
@topherfangio tnx :)

@adibas03
Copy link

Issue Fixed in version 1.13 thanks @topherfangio

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants