1
1
# ngx-numeric-range-form-field
2
2
3
- An Angular Material UI numeric range input form field. It is based on custom form field control and control value accessor which allows inserting range numbers, minimum and maximum.
3
+ 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.
4
4
5
5
![ Numeric range form field] ( https://github.com/dineeek/ngx-numeric-range-form-field/blob/main/ngx-numeric-range-form-field/Numeric%20Range%20Form%20Field.png )
6
6
@@ -16,8 +16,8 @@ An Angular Material UI numeric range input form field. It is based on custom for
16
16
# Feature
17
17
18
18
- Two inputs as one field.
19
- - Auto range validation .
20
- - Supports reactive forms .
19
+ - Reactive form field .
20
+ - Auto range validation & custom validation .
21
21
22
22
** [ View live demo on StackBlitz.] ( https://ngx-numeric-range-form-field.stackblitz.io ) **
23
23
@@ -29,20 +29,20 @@ npm install ngx-numeric-range-form-field
29
29
30
30
# Usage
31
31
32
- In component HTML :
32
+ Template :
33
33
34
34
``` html
35
- <ngx-numeric-range-form-field
36
- [formControl] =" rangeControl"
37
- label =" Numeric range"
38
- (blurred) =" onBlur()"
39
- (enterPressed) =" onEnter()"
40
- (numericRangeChanged) =" onValueChange($event)"
41
- ></ngx-numeric-range-form-field >
35
+ <form [formGroup] =" form" >
36
+ <ngx-numeric-range-form-field
37
+ formControlName =" range"
38
+ label =" Numeric range"
39
+ (blurred) =" onBlur()"
40
+ (enterPressed) =" onEnter()"
41
+ (numericRangeChanged) =" onNumericRangeChanged($event)"
42
+ ></ngx-numeric-range-form-field >
43
+ </form >
42
44
```
43
45
44
- In component.ts:
45
-
46
46
``` typescript
47
47
form : FormGroup ;
48
48
@@ -59,10 +59,6 @@ form: FormGroup;
59
59
});
60
60
}
61
61
62
- get rangeControl (): FormControl {
63
- return this .form .get (' range' ) as FormControl ;
64
- }
65
-
66
62
onBlur (): void {
67
63
console .log (' Value' , this .rangeControl .value );
68
64
}
@@ -71,45 +67,91 @@ form: FormGroup;
71
67
console .log (' Enter pressed!' );
72
68
}
73
69
74
- onValueChange (value : INumericRange ): void {
70
+ onNumericRangeChanged (value : INumericRange ): void {
75
71
console .log (' Changed value: ' , value );
76
72
}
77
73
```
78
74
79
- Customizable input and output decorators :
75
+ It is based on following type :
80
76
81
77
``` typescript
82
- @Input () label : string ; // Label of the control
83
- @Input () appearance : ' legacy' | ' standard' | ' fill' | ' outline' = ' outline' ;
84
- @Input () floatLabel : ' always' | ' never' | ' auto' = ' always' ;
85
- @Input () minPlaceholder = ' From' ; // Placeholder of the minimum value control
86
- @Input () maxPlaceholder = ' To' ; // Placeholder of the maximum value control
87
- @Input () readonly = false ; // Flag for readonly both controls
88
- @Input () minReadonly = false ; // Flag for readonly minimum control
89
- @Input () maxReadonly = false ; // Flag for readonly maximum control
90
- @Input () resettable = true ; // Flag for resetting controls value
91
- @Input () requiredErrorMessage = ' Field is required!' ; // Customizable error message when field is required
92
- @Input () minimumErrorMessage = ' Minimum has been reached!' ; // Customizable error message when field has min validation
93
- @Input () maximumErrorMessage = ' Maximum has exceeded!' ; // Customizable error message when field has max validation
94
- @Input () invalidRangeErrorMessage = ' Inserted range is not valid!' ; // Customizable error message when field has invalid numeric range
95
- @Input () dynamicSyncValidators : ValidatorFn | ValidatorFn []; // Dynamic change of sync validators
96
-
97
- @Output () blurred = new EventEmitter <void >(); // Event which emits where user leaves control (focus out)
98
- @Output () enterPressed = new EventEmitter <void >(); // Event which emits when enter is pressed
99
- @Output () numericRangeChanged = new EventEmitter <INumericRange >(); // Event which emits when one of range value is changed
100
- ```
101
-
102
- It is based on following interface:
103
-
104
- ``` typescript
105
- export interface INumericRange {
78
+ type INumericRange = {
106
79
minimum: number ;
107
80
maximum: number ;
108
- }
81
+ };
109
82
```
110
83
84
+ ### Input property decorators:
85
+
86
+ - #### label
87
+
88
+ Set label of the field.
89
+
90
+ - #### appearance
91
+
92
+ Set MatFormFieldAppearance.
93
+
94
+ - #### floatLabel
95
+
96
+ Set FloatLabelType.
97
+
98
+ - #### minPlaceholder & maxPlaceholder
99
+
100
+ Set placeholder of the minimum value control. Defaulted to 'From'.
101
+ Set placeholder of the maximum value control. Defaulted to 'To'.
102
+
103
+ - #### readonly
104
+
105
+ Set field value as readonly.
106
+
107
+ - #### minReadonly & maxReadonly
108
+
109
+ Set flag for separated readonly value.
110
+
111
+ - #### resettable
112
+
113
+ Set showing icon for resetting value in field.
114
+
115
+ - #### requiredErrorMessage
116
+
117
+ Set error message on required validation.
118
+
119
+ - #### minimumErrorMessage & maximumErrorMessage
120
+
121
+ Set error message on min & max value validation.
122
+
123
+ - #### maximumErrorMessage
124
+
125
+ Set error message on min value validation.
126
+
127
+ - #### invalidRangeErrorMessage
128
+
129
+ Set error message on invalid numeric range.
130
+
131
+ - #### dynamicSyncValidators
132
+
133
+ Set sync validators on runtime.
134
+
135
+ ### Output property decorators:
136
+
137
+ - #### blurred
138
+
139
+ Emit on blur out.
140
+
141
+ - #### enterPressed
142
+
143
+ Emit on enter press.
144
+
145
+ - #### numericRangeChanged
146
+
147
+ Emit on value change.
148
+
149
+ # Contributing
150
+
151
+ Contributions are more than welcome!
152
+
111
153
# License
112
154
113
- Apache License
155
+ MIT License
114
156
115
157
Copyright (c) 2022 Dino Klicek
0 commit comments