From bf02c1b99ec50f665bfece94e451b7954dd281a6 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Mon, 24 Aug 2020 15:24:55 +0200 Subject: [PATCH] added required parameter range --- src/app/sample/sample.component.ts | 10 +++++----- src/app/services/validation.service.ts | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/sample/sample.component.ts b/src/app/sample/sample.component.ts index cfac79e..cdcfa03 100644 --- a/src/app/sample/sample.component.ts +++ b/src/app/sample/sample.component.ts @@ -239,12 +239,12 @@ export class SampleComponent implements OnInit, AfterContentChecked { this.samples.forEach((gSample, gIndex) => { if (this.d.id.conditionTemplates[gSample.condition.condition_template]) { this.d.id.conditionTemplates[gSample.condition.condition_template].parameters.forEach((parameter, pIndex) => { - this.attachValidator(this.cmForm, `conditionParameter-${gIndex}-${pIndex}`, parameter.range, true); + this.attachValidator(this.cmForm, `conditionParameter-${gIndex}-${pIndex}`, parameter.range); }); } gSample.measurements.forEach((measurement, mIndex) => { this.d.id.measurementTemplates[measurement.measurement_template].parameters.forEach((parameter, pIndex) => { - this.attachValidator(this.cmForm, `measurementParameter-${gIndex}-${mIndex}-${pIndex}`, parameter.range, false); + this.attachValidator(this.cmForm, `measurementParameter-${gIndex}-${mIndex}-${pIndex}`, parameter.range); }); }); }); @@ -252,7 +252,7 @@ export class SampleComponent implements OnInit, AfterContentChecked { if (this.sampleForm && this.material.properties.material_template) { // material template is set this.d.id.materialTemplates[this.material.properties.material_template].parameters.forEach((parameter, i) => { - this.attachValidator(this.sampleForm, 'materialParameter' + i, parameter.range, true); + this.attachValidator(this.sampleForm, 'materialParameter' + i, parameter.range); }); } @@ -288,10 +288,10 @@ export class SampleComponent implements OnInit, AfterContentChecked { } // attach validators specified in range to input with name - attachValidator(form, name: string, range: {[prop: string]: any}, required: boolean) { + attachValidator(form, name: string, range: {[prop: string]: any}) { if (form && form.form.get(name)) { const validators = []; - if (required) { + if (range.hasOwnProperty('required')) { validators.push(Validators.required); } if (range.hasOwnProperty('values')) { diff --git a/src/app/services/validation.service.ts b/src/app/services/validation.service.ts index 0deb86e..8584154 100644 --- a/src/app/services/validation.service.ts +++ b/src/app/services/validation.service.ts @@ -153,13 +153,12 @@ export class ValidationService { max: Joi.number(), type: Joi.string() - .valid('array') + .valid('string', 'number', 'boolean', 'array'), + + required: Joi.boolean() }) .oxor('values', 'min') .oxor('values', 'max') - .oxor('type', 'values') - .oxor('type', 'min') - .oxor('type', 'max') .required() .validate(JSON.parse(data)); if (error) {