-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Select with ngRequired not invalid with unmatched Model set from scope #13172
Comments
Oh, yes when the select has ngRequired, it should add the required error. Looks like a bug.
|
The problem is that the select element has its value property set to whatever is set on the scope, even if there's an error somewhere. That makes sense for inputs, because they would otherwise be empty. required uses this value to check if a control is "empty", and if it is, sets the error. Select is a special case, though ... I could see how it would make sense to set the error if the model finds not match in the options. Wdyt @petebacondarwin? |
I didn't think we did validation on programmatic changes for any input control? |
@Narretz, just to be clear, are you suggesting that the |
Yes, that would be the change. For the other question, we do validate after the model is programmatically
|
OK, so setting the value of a select so that the unknown option is displayed should cause |
I think rather than labeling this as a bug with The challenge I'm facing when thinking about this issue is that The solution this issue is requesting would only support using |
If we can agree that the select should be invalid when the model is not matched by any option, we should fix this in the pure select, too. Required uses a function in the ngModelController called isEmpty which is called with the current viewValue and when it returns true it will set the required error. Select and ngOptions overwrite this function with their own implementation. To fix this bug we should account for the unmatched case in this logic. |
I agree with @Narretz - this should be fixed by providing a better |
Ah I see. Thanks for clearing that up! |
ngOptions overwrite isEmpty function is case of multiple select only, I have solved this problem we have the following cases 1 - case attr.required is false i return true 2 - case $isEmpty(viewValue) return false 3 - case is required and not empty now we need to validate that value is one of the options i think this are the cases that solve the problem. a - select in multiple and value is an array b - select is a single value so this value must be one of the select options to return true |
Any news on when we should expect this fix? |
Any chance you can take a look at this @Narretz ? |
I already did iirc correctly, just didn't open a PR for some reason |
…wn option selected With this patch, a regular / ngOptions select with the "required" attribute will now add the "required" error to the ngModel if the *unknown" option is selected. Previously, the error was only set if the *empty* option was selected. The unknown option is selected if the model is set to a value that does not match any option. If the select has an empty option, this option is selected when the model is `null` or `undefined`. For both, "required" means that the select is invalid, as no correct option selection is provided. Closes angular#13354 Fixes angular#13172
…wn option selected With this patch, a regular / ngOptions select with the "required" attribute will now add the "required" error to the ngModel if the *unknown" option is selected. Previously, the error was only set if the *empty* option was selected. The unknown option is selected if the model is set to a value that does not match any option. If the select has an empty option, this option is selected when the model is `null` or `undefined`. For both, "required" means that the select is invalid, as no correct option selection is provided. Closes angular#13354 Fixes angular#13172
This allows custom directives to manipulate the select's and ngModel's behavior based on the state of the unknown and the empty option. Closes angular#13172 Closes angular#10127
This allows custom directives to manipulate the select's and ngModel's behavior based on the state of the unknown and the empty option. Closes angular#13172 Closes angular#10127
This allows custom directives to manipulate the select's and ngModel's behavior based on the state of the unknown and the empty option. Closes angular#13172 Closes angular#10127
I might have found some inconsistency in select validity. When setting the model to a value not listed in options, the form controller remains valid. I think the right behavior would be an invalid state, as the model is not matching the range of available options.
http://plnkr.co/edit/2qm7P1ag2wMCYOwDGRsF
The text was updated successfully, but these errors were encountered: