required validation

This commit is contained in:
annampak 2018-01-08 13:50:43 +02:00
parent 693dfc5bb0
commit cb6d46256c
5 changed files with 24 additions and 5 deletions

View File

@ -52,7 +52,10 @@
<div [hidden]="isValid">
<div class="invalid-feedbackCustom" *ngIf="isValidRequired">The field "{{field.label}}" is required</div>
<mat-error *ngIf="isValidRequired">
The field "{{field.title}}" <strong>required</strong>
</mat-error>
<!-- <div class="invalid-feedbackCustom" *ngIf="isValidRequired">The field "{{field.label}}" is required</div> -->
<div class="invalid-feedbackCustom" *ngIf="isValidPattern">The field {{field.label}} must match a regular expression {{field.regex}}</div>
<div class="invalid-feedbackCustom" *ngIf="isValidCustom">The field {{field.label}} custom Validation</div>
</div>

View File

@ -31,6 +31,9 @@ export class DynamicFormFieldComponent {
ngOnChanges(changeRecord) {
}
ngOnInit(){
debugger;
}
clearInput(){
debugger;

View File

@ -22,13 +22,13 @@ export class DynamicFormCompositeFieldComponent implements OnInit {
constructor(private visibilityRulesService: VisibilityRulesService) { }
ngOnInit() {
debugger;
console.log(this.form);
if (this.compositeField.hasCommentField == true) {
let newfield: Field = new Field();
newfield.id = 'comment_' + this.compositeField.id;
newfield.data = {label: "Comments"};
newfield.viewStyle = {renderStyle: 'freetext', cssClass: ''};
newfield.validations = ["None"]
this.compositeField.fields.push(newfield);
(<FormArray>this.form.get("fields")).push(newfield.buildForm());

View File

@ -89,6 +89,9 @@ export class DynamicFormComponent implements OnInit {
submit() {
//this.serverService.updateDataset(this.datasetId, this.form.value).subscribe()
}
save(){
debugger;
}
toggleSidebar() {
this.visibleSidebar = !this.visibleSidebar;

View File

@ -1,5 +1,5 @@
import { BaseModel } from './BaseModel';
import { FormGroup } from '@angular/forms';
import { FormGroup, Validators } from '@angular/forms';
import { FormGenerator } from './interfaces/FormGenerator';
import { JsonSerializer } from '../utilities/JsonSerializer';
import { Serializable } from './interfaces/Serializable';
@ -21,7 +21,7 @@ export class Field extends BaseModel implements Serializable<Field>, FormGenerat
public multiplicity: Multiplicity;
public multiplicityItems: Array<Field> = new Array<Field>();
public data: any;
public validations: Array<ValidationTypes>;
public validations: Array<any>;//Array<ValidationTypes>
fromJSONObject(item: any): Field {
this.id = item.id;
@ -43,12 +43,22 @@ export class Field extends BaseModel implements Serializable<Field>, FormGenerat
return this;
}
buildForm(): FormGroup {
let validationRequired = "false";
if(this.validations)
this.validations.forEach(validation => {
if (validation == "REQUIRED")
{validationRequired = "true";}
});
let formGroup = this.formBuilder.group({
id: [this.id],
data:[this.data],
/* title: [this.title], */
value: [this.value]/* ,
value: [this.value, validationRequired == "true"? Validators.required:null]/* ,
description: [this.description],
extendedDescription:[this.extendedDescription],
viewStyle: [this.viewStyle],