Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Interval Value Validators): Propagate valueRequiredValidator to child component (DSP-1193) #253

Merged
merged 7 commits into from Jan 13, 2021

Conversation

mdelez
Copy link
Contributor

@mdelez mdelez commented Jan 8, 2021

resolves DSP-1193

@mdelez mdelez added the bug Something isn't working label Jan 8, 2021
@mdelez mdelez self-assigned this Jan 8, 2021
@mdelez mdelez changed the title DSP-1193 - Interval Value Component Validators fix(Interval Value Validators): Propagate valueRequiredValidator to child component (DSP-1193) Jan 11, 2021
@mdelez
Copy link
Contributor Author

mdelez commented Jan 11, 2021

@tobiasschweizer same thing as #251 but for the interval value component

@@ -11,4 +11,10 @@
End is <strong>required</strong>.
</mat-error>
</mat-form-field>

<div class="date-form-error">
<mat-error *ngIf="((startIntervalControl.hasError('startEndSameTypeRequired') || endIntervalControl.hasError('startEndSameTypeRequired')))">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for null checks for start or end as in case of the date?
Or is this taken care of by startEndSameTypeValidator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handled in startEndSameTypeValidator

return (control: AbstractControl): { [key: string]: any } | null => {

let invalid = true;
if (typeof(control.value) === 'number' && typeof(otherInterval.value) === 'number' ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just check for null?

Something like invalid = !(control.value === null && otherInterval.value === null || control.value !== null && otherInterval.value !== null)

I think the input only allows for numeric values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was me being overly paranoid. Refactored in 3c0a216

@@ -157,6 +183,16 @@ export class IntervalInputComponent extends _MatInputMixinBase implements Contro
}
}

ngOnInit() {
if (this.valueRequiredValidator) {
this.startIntervalControl.setValidators([Validators.required, startEndSameTypeValidator(this.endIntervalControl)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add the startEndSameTypeValidator also when the required validator is not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, I forgot. Added in 3c0a216


expect(testHostComponent.intervalInputComponent.form.valid).toBe(false);
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case for the startEndSameTypeValidator? Or is this not possible because the required operator will always trigger anyway (start or end is null)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 19f996d

@mdelez
Copy link
Contributor Author

mdelez commented Jan 13, 2021

@flavens With these changes, you can make an interval not required. However you will still see an error message if the interval is not entered correctly (i.e. only the start interval has been entered). There isn't really an intuitive way to disregard this error if the interval is not required because we want to ensure the user enters a valid interval. If the user does not want to enter an interval (both inputs are empty/null), that is allowed and the form will submit.

Screen Shot 2021-01-13 at 10 26 16

In this screenshot, the required validator is set to "false" however the interval only has a start so the user see's an error message. No interval will be submitted to Knora in this state.

As for the Create Resource Form, I would recommend to scroll the user to this component if the user has filled it in only partially even if it is not required. The user should fill in the form correctly by either providing a start and an end or by leaving both inputs empty. The incorrect input will have the ng-invalid class.

@mdelez mdelez merged commit 3424831 into main Jan 13, 2021
@mdelez mdelez deleted the wip/DSP-1193-interval-value-comp-validators branch January 13, 2021 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants