validation type combobox in field

This commit is contained in:
annampak 2018-01-04 13:20:50 +02:00
parent 1d93d2d37e
commit 75614b1229
4 changed files with 60 additions and 43 deletions

View File

@ -1,3 +1,4 @@
export enum ValidationTypes { export enum ValidationTypes {
required None = 0,
Required = 1
} }

View File

@ -78,11 +78,16 @@
</div> </div>
<div class="form-group col-md-5"> <div class="form-group col-md-5">
<label>Validation</label> <label>Validation</label>
<select class="form-control" formControlName="validations"> <div formArrayName="validations">
<option value="required">Required Field</option> <div *ngFor="let validation of form.controls.validations.controls; let i=index">
<select class="form-control" [formControlName]="i">
<option *ngFor= "let option of validationsOptions" [value]="option.key">{{option.value}}</option>
</select> </select>
</div> </div>
</div> </div>
</div>
</div>
</div> </div>
<label *ngIf="showMultiplicity"> <label *ngIf="showMultiplicity">
<input type="checkbox" [(ngModel)]="isFieldMultiplicityEnabled" (ngModelChange)="onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled)" <input type="checkbox" [(ngModel)]="isFieldMultiplicityEnabled" (ngModelChange)="onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled)"

View File

@ -2,6 +2,7 @@
import { Rule } from '../../models/DataSetProfile/Rule'; import { Rule } from '../../models/DataSetProfile/Rule';
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { FormGroup, FormControl, FormArray } from '@angular/forms'; import { FormGroup, FormControl, FormArray } from '@angular/forms';
import { ValidationTypes } from 'app/common/validationTypes';
@Component({ @Component({
selector: 'field-form', selector: 'field-form',
@ -14,15 +15,17 @@ export class FieldFormComponent {
@Input() dataModel: Field; @Input() dataModel: Field;
@Input() showMultiplicity: boolean = true; @Input() showMultiplicity: boolean = true;
@Input() indexPath: string; @Input() indexPath: string;
validationsOptions: Array<any>;
isFieldMultiplicityEnabled: boolean = false; isFieldMultiplicityEnabled: boolean = false;
constructon() { } constructon() {
}
ngOnInit() { ngOnInit() {
if (this.form.get("multiplicity")) if (this.form.get("multiplicity"))
if (this.form.get("multiplicity").value.min > 1 || this.form.get("multiplicity").value.max > 1) if (this.form.get("multiplicity").value.min > 1 || this.form.get("multiplicity").value.max > 1)
this.isFieldMultiplicityEnabled = true; this.isFieldMultiplicityEnabled = true;
this.validationsOptions = [{ key: 0, value: ValidationTypes[0] }, { key: 1, value: ValidationTypes[1] }]
// this.addNewRule(); // this.addNewRule();
} }
@ -43,4 +46,8 @@ export class FieldFormComponent {
this.dataModel.visible.rules.splice(index, 1); this.dataModel.visible.rules.splice(index, 1);
(<FormArray>this.form.get("visible").get("rules")).removeAt(index); (<FormArray>this.form.get("visible").get("rules")).removeAt(index);
} }
onchangeCombo() {
debugger;
}
} }

View File

@ -7,7 +7,7 @@ import { WordListData } from '../DataField/WordListData';
import { AutocompleteData } from '../DataField/AutocompleteData'; import { AutocompleteData } from '../DataField/AutocompleteData';
import { DataField } from '../DataField/DataField'; import { DataField } from '../DataField/DataField';
import { BaseModel } from '../BaseModel'; import { BaseModel } from '../BaseModel';
import { FormGroup } from '@angular/forms'; import { FormGroup, FormArray, FormControl } from '@angular/forms';
import { FormGenerator } from '../interfaces/FormGenerator'; import { FormGenerator } from '../interfaces/FormGenerator';
import { JsonSerializer } from 'app/utilities/JsonSerializer'; import { JsonSerializer } from 'app/utilities/JsonSerializer';
import { Serializable } from '../interfaces/Serializable'; import { Serializable } from '../interfaces/Serializable';
@ -61,11 +61,15 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
id: [this.id], id: [this.id],
title: [this.title], title: [this.title],
page: [this.page], page: [this.page],
ordinal:[this.ordinal], ordinal: [this.ordinal]
validations:[this.validations]
}); });
const arr = new FormArray([
new FormControl(ValidationTypes.None)
]);
//formGroup.addControl("multiplicity", this.multiplicity.buildForm()); //formGroup.addControl("multiplicity", this.multiplicity.buildForm());
formGroup.addControl("validations", arr);
formGroup.addControl("defaultValue", this.defaultValue.buildForm()); formGroup.addControl("defaultValue", this.defaultValue.buildForm());
formGroup.addControl("viewStyle", this.viewStyle.buildForm()); formGroup.addControl("viewStyle", this.viewStyle.buildForm());
formGroup.addControl("visible", this.visible.buildForm()); formGroup.addControl("visible", this.visible.buildForm());