|
//define the state ComboBox countrydata
public countryData: { [key: string]: Object }[] = [
{ CountryName: 'Australia', CountryId: '2' },
{ CountryName: 'United States', CountryId: '1' }
];
//define the state ComboBox statedata
public stateData: { [key: string]: Object }[] = [
{ StateName: 'New York', CountryId: '1', StateId: '101' },
{ StateName: 'Virginia ', CountryId: '1', StateId: '102' },
{ StateName: 'Tasmania ', CountryId: '2', StateId: '105' }
];
|
|
<form [formGroup]="skillForm" novalidate id="formId">
<div class="form-group">
<ejs-combobox #country formControlName="skillname" name="skillname" allowCustom="false" [dataSource]="countryData" [fields]="countryFields" (change)="countryChange()" [placeholder]="countryWatermark">
</ejs-combobox>
<div *ngIf="skillForm.controls.skillname.invalid && skillForm.controls.skillname.touched" class="alert alert-danger">
<div *ngIf="skillForm.controls.skillname.errors.required">
Country is required.
</div>
</div>
</div>
<div class="form-group">
<ejs-combobox #state formControlName="skillname1" name="skillname1" allowCustom="false" [dataSource]="stateData" [fields]="stateFields" [placeholder]="stateWatermark">
</ejs-combobox>
<div *ngIf="skillForm.controls.skillname1.invalid && skillForm.controls.skillname1.touched" class="alert alert-danger">
<div *ngIf="skillForm.controls.skillname1.errors.required">
State is required.
</div>
</div>
</div> |
|
public countryData: { [key: string]: Object }[] = [
{ CountryName: "Australia", CountryId: "2" },
{ CountryName: "United States", CountryId: "1" }
];
public stateData: { [key: string]: Object }[] = [
{ StateName: "New York", CountryId: "1", StateId: "101" },
{ StateName: "Virginia ", CountryId: "1", StateId: "102" },
{ StateName: "Tasmania ", CountryId: "2", StateId: "105" }
];
public countryFields: Object = { text: "CountryName", value: "CountryId" };
public stateFields: Object = { text: "StateName", value: "StateId" };
public countryWatermark: string = "Select a country";
public stateWatermark: string = "Select a state";
@ViewChild("country")
public countryObj: ComboBoxComponent;
@ViewChild("state")
public stateObj: ComboBoxComponent;
skillForm: FormGroup;
public countryChange(): void {
let tempQuery: Query = new Query().where(
"CountryId",
"equal",
this.countryObj.value
);
this.stateObj.query = tempQuery;
this.stateObj.text = null;
this.stateObj.dataBind();
}
constructor(private fb: FormBuilder) {
this.createForm();
}
createForm(): void {
this.skillForm = this.fb.group({
skillname: ["", Validators.required],
skillname1: ["", Validators.required]
});
} |