Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,15 @@ export class ExperimentFormService {
return param;
}

if ((param.feasibleSpace as FeasibleSpaceMinMax).step === '') {
const step = (param.feasibleSpace as FeasibleSpaceMinMax).step;
if (step === '' || step === null) {
delete (param.feasibleSpace as FeasibleSpaceMinMax).step;
}

for (const key in param.feasibleSpace) {
param.feasibleSpace[key] = param.feasibleSpace[key].toString();
}

return param;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ <h1 mat-dialog-title>Add new parameter</h1>
<div class="range-wrapper" [formGroup]="formGroup.get('feasibleSpace')">
<mat-form-field appearance="outline">
<mat-label>Min</mat-label>
<input matInput formControlName="min" />
<input matInput formControlName="min" type="number" />
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>Max</mat-label>
<input matInput formControlName="max" />
<input matInput formControlName="max" type="number" />
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>Step (optional)</mat-label>
<input matInput formControlName="step" />
<input matInput formControlName="step" type="number" />
</mat-form-field>
</div>
</ng-container>
Expand Down
21 changes: 19 additions & 2 deletions pkg/new-ui/v1beta1/frontend/src/app/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import lowerCase from 'lodash-es/lowerCase';
import { FormControl, FormGroup, Validators, FormArray } from '@angular/forms';
import {
FormControl,
FormGroup,
Validators,
FormArray,
ValidatorFn,
AbstractControl,
ValidationErrors,
} from '@angular/forms';
import {
ParameterSpec,
FeasibleSpaceMinMax,
Expand Down Expand Up @@ -31,7 +39,7 @@ export function createFeasibleSpaceGroup(
return new FormGroup({
min: new FormControl(fs.min, Validators.required),
max: new FormControl(fs.max, Validators.required),
step: new FormControl(fs.step, []),
step: new FormControl(fs.step, checkIfZero()),
});
}

Expand Down Expand Up @@ -133,3 +141,12 @@ export const safeMultiplication = (
multiplicand: number,
multiplier: number,
): number => Math.round(multiplicand * 10000.0 * multiplier) / 10000;

export const checkIfZero = (): ValidatorFn => {
return (control: AbstractControl): ValidationErrors | null => {
if (control.value === null || control.value === '') return null;

const isZero = !/[^0.]/g.test(control.value.toString());
return isZero ? { mustNotBeZero: { value: control.value } } : null;
};
};