diff --git a/src/demo/app/app.component.css b/src/demo/app/app.component.css index f5aa842..21ff2f7 100644 --- a/src/demo/app/app.component.css +++ b/src/demo/app/app.component.css @@ -210,3 +210,16 @@ textarea:input:focus { .df-property-control { width: 100%; } + +.invalid-property-value .df-property-label-cell { + color: red; +} + +.invalid-property-value .df-property-control { + outline-color: red; + border-color: red; +} + +.validation-error-block { + color: red; +} diff --git a/src/demo/app/editor.ts b/src/demo/app/editor.ts index f6d3668..93717eb 100644 --- a/src/demo/app/editor.ts +++ b/src/demo/app/editor.ts @@ -15,6 +15,7 @@ */ import { Flo, Constants, Properties } from 'spring-flo'; +import { Validators } from '@angular/forms'; import { dia } from 'jointjs'; import { BsModalService } from 'ngx-bootstrap'; import { PropertiesDialogComponent } from './properties.dialog.component'; @@ -557,6 +558,7 @@ export class Editor implements Flo.Editor { class SamplePropertiesGroupModel extends Properties.PropertiesGroupModel { protected createControlModel(property : Properties.Property) : Properties.ControlModel { let inputType = Properties.InputType.TEXT; + let validation : Properties.Validation; switch (property.metadata.type) { case 'number': inputType = Properties.InputType.NUMBER; @@ -583,8 +585,16 @@ class SamplePropertiesGroupModel extends Properties.PropertiesGroupModel { })); } default: + if (property.metadata.name === 'name') { + validation = { + validator: Validators.required, + errorData: [ + { id: 'required', message: 'Name is required!' } + ] + } + } break; } - return new Properties.GenericControlModel(property, inputType); + return new Properties.GenericControlModel(property, inputType, validation); } } diff --git a/src/lib/src/properties/df.property.component.html b/src/lib/src/properties/df.property.component.html index adc884e..4a00b18 100644 --- a/src/lib/src/properties/df.property.component.html +++ b/src/lib/src/properties/df.property.component.html @@ -1,4 +1,4 @@ - + @@ -32,10 +32,10 @@ - - -

{{model.description}}

-

{{e.message}}

+
+
{{model.description}}
+
{{e.message}}
+
diff --git a/src/lib/src/properties/df.property.component.ts b/src/lib/src/properties/df.property.component.ts index 856ca31..349f3cd 100644 --- a/src/lib/src/properties/df.property.component.ts +++ b/src/lib/src/properties/df.property.component.ts @@ -25,7 +25,8 @@ export class DynamicFormPropertyComponent { } get errorData() { - return (this.model.validation && this.model.validation.errorData ? this.model.validation.errorData : []).map(e => this.control.errors[e.message]); + return (this.model.validation && this.model.validation.errorData ? this.model.validation.errorData : []) + .filter(e => this.control.errors && this.control.errors[e.id]); } }