added required parameter range
This commit is contained in:
parent
65f740af77
commit
bf02c1b99e
@ -239,12 +239,12 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
|||||||
this.samples.forEach((gSample, gIndex) => {
|
this.samples.forEach((gSample, gIndex) => {
|
||||||
if (this.d.id.conditionTemplates[gSample.condition.condition_template]) {
|
if (this.d.id.conditionTemplates[gSample.condition.condition_template]) {
|
||||||
this.d.id.conditionTemplates[gSample.condition.condition_template].parameters.forEach((parameter, pIndex) => {
|
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) => {
|
gSample.measurements.forEach((measurement, mIndex) => {
|
||||||
this.d.id.measurementTemplates[measurement.measurement_template].parameters.forEach((parameter, pIndex) => {
|
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
|
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.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
|
// 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)) {
|
if (form && form.form.get(name)) {
|
||||||
const validators = [];
|
const validators = [];
|
||||||
if (required) {
|
if (range.hasOwnProperty('required')) {
|
||||||
validators.push(Validators.required);
|
validators.push(Validators.required);
|
||||||
}
|
}
|
||||||
if (range.hasOwnProperty('values')) {
|
if (range.hasOwnProperty('values')) {
|
||||||
|
@ -153,13 +153,12 @@ export class ValidationService {
|
|||||||
max: Joi.number(),
|
max: Joi.number(),
|
||||||
|
|
||||||
type: Joi.string()
|
type: Joi.string()
|
||||||
.valid('array')
|
.valid('string', 'number', 'boolean', 'array'),
|
||||||
|
|
||||||
|
required: Joi.boolean()
|
||||||
})
|
})
|
||||||
.oxor('values', 'min')
|
.oxor('values', 'min')
|
||||||
.oxor('values', 'max')
|
.oxor('values', 'max')
|
||||||
.oxor('type', 'values')
|
|
||||||
.oxor('type', 'min')
|
|
||||||
.oxor('type', 'max')
|
|
||||||
.required()
|
.required()
|
||||||
.validate(JSON.parse(data));
|
.validate(JSON.parse(data));
|
||||||
if (error) {
|
if (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user