An Angular Material UI numeric range input form field. Implementation is based on custom form field and control value accessor which allows inserting range numbers - minimum and maximum.
- Two inputs as one field.
- Reactive form field.
- Auto range validation & custom validation.
npm install ngx-numeric-range-form-field
Template:
<form [formGroup]="form">
<ngx-numeric-range-form-field
formControlName="range"
label="Numeric range"
(blurred)="onBlur()"
(enterPressed)="onEnter()"
(numericRangeChanged)="onNumericRangeChanged($event)"
></ngx-numeric-range-form-field>
</form>
form: FormGroup;
constructor() {
this.form = new FormGroup({
range: new FormControl({
minimum: 10,
maximum: 100,
}, [
Validators.required, //optional
Validators.min(10), //optional
Validators.max(100), //optional
]),
});
}
onBlur(): void {
console.log('Value', this.rangeControl.value);
}
onEnter(): void {
console.log('Enter pressed!');
}
onNumericRangeChanged(value: INumericRange): void {
console.log('Changed value: ', value);
}
It is based on following type:
type INumericRange = {
minimum: number;
maximum: number;
};
-
Set label of the field.
-
Set MatFormFieldAppearance.
-
Set FloatLabelType.
-
Set placeholder of the minimum value control. Defaulted to 'From'. Set placeholder of the maximum value control. Defaulted to 'To'.
-
Set field value as readonly.
-
Set flag for separated readonly value.
-
Set showing icon for resetting value in field.
-
Set error message on required validation.
-
Set error message on min & max value validation.
-
Set error message on min value validation.
-
Set error message on invalid numeric range.
-
Set sync validators on runtime.
-
Emit on blur out.
-
Emit on enter press.
-
Emit on value change.
Contributions are more than welcome!
MIT License
Copyright (c) 2022 Dino Klicek