JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 515
  • Score
    100M100P100Q106146F
  • License Apache

Custom numeric range input form field

Package Exports

  • ngx-numeric-range-form-field

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ngx-numeric-range-form-field) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ngx-numeric-range-form-field

An Angular Material UI numeric range input form field. It is based on custom form field control and control value accessor which allows inserting minimum number and maximum number of some range.

Numeric range form field

weekly downloads from npm npm version

Maintenance code style: prettier FOSSA Status

Feature

  • Two inputs as one field.
  • Auto range validation.
  • Supports reactive forms.

View live demo on StackBlitz.

Install

npm install ngx-numeric-range-form-field

Usage

In component HTML:

<ngx-numeric-range-form-field-container
    [formControl]="rangeControl"
    label="Numeric range"
    (blurred)="onBlur()"
    (enterPressed)="onEnter()"
    (numericRangeChanged)="onValueChange($event)"
></ngx-numeric-range-form-field-container>

In component.ts:

form: FormGroup;

    constructor() {
        this.form = new FormGroup({
            range: new FormControl(null, [
                Validators.required, //optional
                Validators.min(10), //optional
                Validators.max(100), //optional
            ]),
        });
    }

    get rangeControl(): FormControl {
        return this.form.get('range') as FormControl;
    }

    onBlur(): void {
        console.log('Value', this.rangeControl.value);
    }

    onEnter(): void {
        console.log('Enter pressed!');
    }

    onValueChange(value: INumericRange): void {
        console.log('Changed value: ', value);
    }

Customizable input and output decorators:

@Input() label: string; // Label of the control
@Input() appearance: 'legacy' | 'standard' | 'fill' | 'outline' = 'outline';
@Input() floatLabel: 'always' | 'never' | 'auto' = 'always';
@Input() minPlaceholder = 'From'; // Placeholder of the minimum value control
@Input() maxPlaceholder = 'To'; // Placeholder of the maximum value control
@Input() readonly = false; // Indicator wether the both controls are readonly
@Input() resettable = true; // Indicator wether the both controls are resettable
@Input() required: boolean; // Required validation
@Input() requiredErrorMessage = 'Field is required!'; // Customizable error message when field is required
@Input() minimumErrorMessage = 'Minimum has been reached!'; // Customizable error message when field has min validation
@Input() maximumErrorMessage = 'Maximum has exceeded!'; // Customizable error message when field has max validation
@Input() invalidRangeErrorMessage = 'Inserted range is not valid!'; // Customizable error message when field has invalid numeric range

@Output() blurred = new EventEmitter<void>(); // Event which emits where user leaves control (focus out)
@Output() enterPressed = new EventEmitter<void>(); // Event which emits when enter is pressed
@Output() numericRangeChanged = new EventEmitter<INumericRange>(); // Event which emits when one of range value is changed

It is based on following interface:

export interface INumericRange {
    minimum: number;
    maximum: number;
}

License

Apache License

Copyright (c) 2021 Dino Klicek