validation type combobox in field
This commit is contained in:
parent
1d93d2d37e
commit
75614b1229
|
@ -1,3 +1,4 @@
|
|||
export enum ValidationTypes {
|
||||
required
|
||||
}
|
||||
None = 0,
|
||||
Required = 1
|
||||
}
|
|
@ -78,9 +78,14 @@
|
|||
</div>
|
||||
<div class="form-group col-md-5">
|
||||
<label>Validation</label>
|
||||
<select class="form-control" formControlName="validations">
|
||||
<option value="required">Required Field</option>
|
||||
</select>
|
||||
<div formArrayName="validations">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { Rule } from '../../models/DataSetProfile/Rule';
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { FormGroup, FormControl, FormArray } from '@angular/forms';
|
||||
import { ValidationTypes } from 'app/common/validationTypes';
|
||||
|
||||
@Component({
|
||||
selector: 'field-form',
|
||||
|
@ -14,15 +15,17 @@ export class FieldFormComponent {
|
|||
@Input() dataModel: Field;
|
||||
@Input() showMultiplicity: boolean = true;
|
||||
@Input() indexPath: string;
|
||||
|
||||
validationsOptions: Array<any>;
|
||||
isFieldMultiplicityEnabled: boolean = false;
|
||||
|
||||
constructon() { }
|
||||
constructon() {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
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"))
|
||||
if (this.form.get("multiplicity").value.min > 1 || this.form.get("multiplicity").value.max > 1)
|
||||
this.isFieldMultiplicityEnabled = true;
|
||||
this.validationsOptions = [{ key: 0, value: ValidationTypes[0] }, { key: 1, value: ValidationTypes[1] }]
|
||||
// this.addNewRule();
|
||||
}
|
||||
|
||||
|
@ -43,4 +46,8 @@ export class FieldFormComponent {
|
|||
this.dataModel.visible.rules.splice(index, 1);
|
||||
(<FormArray>this.form.get("visible").get("rules")).removeAt(index);
|
||||
}
|
||||
|
||||
onchangeCombo() {
|
||||
debugger;
|
||||
}
|
||||
}
|
|
@ -7,70 +7,74 @@ import { WordListData } from '../DataField/WordListData';
|
|||
import { AutocompleteData } from '../DataField/AutocompleteData';
|
||||
import { DataField } from '../DataField/DataField';
|
||||
import { BaseModel } from '../BaseModel';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { FormGroup, FormArray, FormControl } from '@angular/forms';
|
||||
import { FormGenerator } from '../interfaces/FormGenerator';
|
||||
import { JsonSerializer } from 'app/utilities/JsonSerializer';
|
||||
import { Serializable } from '../interfaces/Serializable';
|
||||
import {Rule} from './Rule';
|
||||
import {Multiplicity} from './Multiplicity';
|
||||
import {DefaultValue} from './DefaultValue';
|
||||
import {ViewStyle} from './ViewStyle';
|
||||
import {Visibility} from './Visibility';
|
||||
import { Rule } from './Rule';
|
||||
import { Multiplicity } from './Multiplicity';
|
||||
import { DefaultValue } from './DefaultValue';
|
||||
import { ViewStyle } from './ViewStyle';
|
||||
import { Visibility } from './Visibility';
|
||||
import { ValidationTypes } from 'app/common/validationTypes';
|
||||
|
||||
export class Field extends BaseModel implements Serializable<Field>,FormGenerator<FormGroup>{
|
||||
export class Field extends BaseModel implements Serializable<Field>, FormGenerator<FormGroup>{
|
||||
|
||||
public id:string;
|
||||
public title:string;
|
||||
public defaultValue:DefaultValue = new DefaultValue;
|
||||
public viewStyle:ViewStyle = new ViewStyle();
|
||||
public page:number;
|
||||
public id: string;
|
||||
public title: string;
|
||||
public defaultValue: DefaultValue = new DefaultValue;
|
||||
public viewStyle: ViewStyle = new ViewStyle();
|
||||
public page: number;
|
||||
//public multiplicity: Multiplicity = new Multiplicity();
|
||||
public ordinal: number;
|
||||
public visible: Visibility = new Visibility();
|
||||
public data:DataField<any>;
|
||||
public data: DataField<any>;
|
||||
public validations: Array<ValidationTypes>;
|
||||
|
||||
fromJSONObject(item:any):Field{
|
||||
fromJSONObject(item: any): Field {
|
||||
this.id = item.id;
|
||||
this.title = item.title;
|
||||
this.defaultValue = new JsonSerializer<DefaultValue>().fromJSONObject(item.defaultValue, DefaultValue);
|
||||
this.defaultValue = new JsonSerializer<DefaultValue>().fromJSONObject(item.defaultValue, DefaultValue);
|
||||
this.page = item.page;
|
||||
// this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
|
||||
// this.multiplicity = new JsonSerializer<Multiplicity>().fromJSONObject(item.multiplicity, Multiplicity);
|
||||
this.ordinal = item.ordinal;
|
||||
this.validations = item.validations;
|
||||
this.viewStyle = new JsonSerializer<ViewStyle>().fromJSONObject(item.viewStyle, ViewStyle);
|
||||
this.visible = new JsonSerializer<Visibility>().fromJSONObject(item.visible, Visibility);
|
||||
if(item.data) {
|
||||
if(this.viewStyle.renderStyle === "combobox"){
|
||||
if(item.data.type === "autocomplete") this.data = new JsonSerializer<AutocompleteData>().fromJSONObject(item.data,AutocompleteData);
|
||||
if(item.data.type === "wordlist")this.data = new JsonSerializer<WordListData>().fromJSONObject(item.data,WordListData);
|
||||
}else{
|
||||
if(this.viewStyle.renderStyle === "radiobox") this.data = new JsonSerializer<RadioBoxData>().fromJSONObject(item.data,RadioBoxData);
|
||||
if(this.viewStyle.renderStyle === "checkBox") this.data = new JsonSerializer<CheckBoxData>().fromJSONObject(item.data,CheckBoxData);
|
||||
if(this.viewStyle.renderStyle === "textarea") this.data = new JsonSerializer<TextArea>().fromJSONObject(item.data,TextArea);
|
||||
if(this.viewStyle.renderStyle === "freetext") this.data = new JsonSerializer<FreeTextData>().fromJSONObject(item.data,FreeTextData);
|
||||
if(this.viewStyle.renderStyle === "booleanDecision") this.data = new JsonSerializer<BooleanDecisionData>().fromJSONObject(item.data,BooleanDecisionData);
|
||||
if (item.data) {
|
||||
if (this.viewStyle.renderStyle === "combobox") {
|
||||
if (item.data.type === "autocomplete") this.data = new JsonSerializer<AutocompleteData>().fromJSONObject(item.data, AutocompleteData);
|
||||
if (item.data.type === "wordlist") this.data = new JsonSerializer<WordListData>().fromJSONObject(item.data, WordListData);
|
||||
} else {
|
||||
if (this.viewStyle.renderStyle === "radiobox") this.data = new JsonSerializer<RadioBoxData>().fromJSONObject(item.data, RadioBoxData);
|
||||
if (this.viewStyle.renderStyle === "checkBox") this.data = new JsonSerializer<CheckBoxData>().fromJSONObject(item.data, CheckBoxData);
|
||||
if (this.viewStyle.renderStyle === "textarea") this.data = new JsonSerializer<TextArea>().fromJSONObject(item.data, TextArea);
|
||||
if (this.viewStyle.renderStyle === "freetext") this.data = new JsonSerializer<FreeTextData>().fromJSONObject(item.data, FreeTextData);
|
||||
if (this.viewStyle.renderStyle === "booleanDecision") this.data = new JsonSerializer<BooleanDecisionData>().fromJSONObject(item.data, BooleanDecisionData);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
buildForm():FormGroup{
|
||||
buildForm(): FormGroup {
|
||||
let formGroup = this.formBuilder.group({
|
||||
id: [this.id],
|
||||
title: [this.title],
|
||||
page:[this.page] ,
|
||||
ordinal:[this.ordinal],
|
||||
validations:[this.validations]
|
||||
title: [this.title],
|
||||
page: [this.page],
|
||||
ordinal: [this.ordinal]
|
||||
});
|
||||
|
||||
//formGroup.addControl("multiplicity", this.multiplicity.buildForm());
|
||||
const arr = new FormArray([
|
||||
new FormControl(ValidationTypes.None)
|
||||
]);
|
||||
|
||||
//formGroup.addControl("multiplicity", this.multiplicity.buildForm());
|
||||
formGroup.addControl("validations", arr);
|
||||
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("data",this.data? this.data.buildForm():this.formBuilder.group({}));
|
||||
if(this.data)formGroup.addControl("data",this.data.buildForm());
|
||||
if (this.data) formGroup.addControl("data", this.data.buildForm());
|
||||
|
||||
return formGroup;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue