-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Closed
Labels
area: formseffort1: hourshelp wantedAn issue that is suitable for a community contributor (based on its complexity/scope).An issue that is suitable for a community contributor (based on its complexity/scope).type: bug/fix
Milestone
Description
I have a required select with enum values options :
export enum Pricing {
VALUE0,
VALUE1,
VALUE2
}
@Component({
selector: 'home',
template: `
Welcome Home
<form>
<select id="pricing"
[ngModel]="pricingModel"
(change)="onPricingChanged($event)"
ngControl="pricingControl" required>
<option *ngFor="#pricing of allPricings"
[value]="pricing">
{{ getPricingLabel(pricing) }}
</option>
</select>
{{ pricingModel }}
`,
styles: [`
.ng-invalid { border: 2px solid red; }
`]
viewProviders: [FORM_DIRECTIVES]
})
export class Home {
pricingModel: Pricing;
allPricings: Pricing[] = [
Pricing.VALUE0,
Pricing.VALUE1,
Pricing.VALUE2
];
constructor() {
this.pricingModel = Pricing.VALUE0;
}
onPricingChanged(event) {
var value:string = event.target.value;
var pricing:Pricing = <Pricing>parseInt(value);
this.pricingModel = pricing;
}
getPricingLabel(pricing: Pricing) {
return Pricing[pricing];
}
}
Using this code, the control is marked as invalid when selecting the first value.
plunker: http://plnkr.co/edit/ABh8pzp1afXkINcunKR8?p=preview
Metadata
Metadata
Assignees
Labels
area: formseffort1: hourshelp wantedAn issue that is suitable for a community contributor (based on its complexity/scope).An issue that is suitable for a community contributor (based on its complexity/scope).type: bug/fix