Skip to content

Commit

Permalink
Fixes missing required message
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jan 22, 2019
1 parent 1ecda3f commit 6c40358
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/src/main/resources/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ message.org-incomplete=These three fields must all be entered if any single fiel
message.type-required=Missing required property: Type
message.match-required=Missing required property: Match
message.value-required=Missing required property: Value
message.required=Field is required.

message.conflict=Conflict
message.data-version-contention=Data Version Contention
Expand Down
22 changes: 22 additions & 0 deletions ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
}

getValidators(entityIdList: string[]): { [key: string]: any } {
const checkRequiredChild = (value, property, form) => {
if (!value) {
return {
code: 'REQUIRED',
path: `#${property.path}`,
message: `message.required`,
params: [value]
};
}
return null;
};
const checkRequiredChildren = (value, property, form) => {
let errors;
Object.keys(value).forEach((item, index, all) => {
const error = checkRequiredChild(item, { path: `${index}` }, form);
if (error) {
errors = errors || [];
errors.push(error);
}
});
return errors;
};
const checkOrg = (value, property, form) => {
const org = property.parent;
const orgValue = org.value || {};
Expand Down
25 changes: 22 additions & 3 deletions ui/src/app/schema-form/widget/string/string.component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import { Component } from '@angular/core';
import { Component, AfterViewInit, OnDestroy } from '@angular/core';
import { StringWidget } from 'ngx-schema-form';
import { Validators } from '@angular/forms';
import { SchemaService } from '../../service/schema.service';
import { startWith } from 'rxjs/operators';
import { Subscription } from 'rxjs';

@Component({
selector: 'custom-string',
templateUrl: `./string.component.html`,
styleUrls: ['../widget.component.scss']
})
export class CustomStringComponent extends StringWidget {
export class CustomStringComponent extends StringWidget implements AfterViewInit, OnDestroy {

errorSub: Subscription;

constructor(
private widgetService: SchemaService
) {
super();
}

ngAfterViewInit(): void {
super.ngAfterViewInit();
this.errorSub = this.control.valueChanges.pipe(startWith(this.control.value)).subscribe(v => {
if (!v && this.required && this.errorMessages.some(msg => !!msg.toLowerCase().match('required').length)) {
this.errorMessages.push('message.required');
}
});
}

ngOnDestroy(): void {
this.errorSub.unsubscribe();
}

get required(): boolean {
return this.widgetService.isRequired(this.formProperty);
const req = this.widgetService.isRequired(this.formProperty);

return req;
}
}

0 comments on commit 6c40358

Please sign in to comment.