File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,14 @@ the [Properties table](#properties) for the full list of options.
165165<br />
166166```
167167
168+ ### Min Max Validation
169+
170+ ``` html:preview
171+ <zn-input type="date" label="Input type: Date" placeholder="Date" help-text="Calendar icon opens the browser default date picker" min="01/01/1970"></zn-input>
172+ <br />
173+ <zn-input type="number" label="Input type: Number" min="10" max="100"></zn-input>
174+ ```
175+
168176### Prefix & Suffix Icons
169177
170178Several input types have specific ` prefix ` and ` suffix ` elements or icons that are displayed by default. You can also
Original file line number Diff line number Diff line change @@ -245,8 +245,21 @@ export default class ZnInput extends ZincElement implements ZincFormControl {
245245 return this . input . validationMessage ;
246246 }
247247
248+ private validateMinMax ( ) : void {
249+ if ( this . type !== 'number' && this . type !== 'date' ) {
250+ return ;
251+ }
252+ if ( typeof this . min !== 'undefined' && parseInt ( this . value as string ) < parseInt ( this . min as string ) ) {
253+ this . value = this . min . toString ( ) ;
254+ }
255+ if ( typeof this . max !== 'undefined' && parseInt ( this . value as string ) > parseInt ( this . max as string ) ) {
256+ this . value = this . max . toString ( ) ;
257+ }
258+ }
259+
248260 private handleBlur ( ) {
249261 this . hasFocus = false ;
262+ this . validateMinMax ( ) ;
250263 this . emit ( 'zn-blur' ) ;
251264 }
252265
@@ -464,7 +477,7 @@ export default class ZnInput extends ZincElement implements ZincFormControl {
464477 'input--disabled' : this . disabled ,
465478 'input--focused' : this . hasFocus ,
466479 'input--empty' : ! this . value ,
467- 'input--no-spin-buttons' : this . noSpinButtons || this . type !== 'currency' ,
480+ 'input--no-spin-buttons' : this . noSpinButtons && this . type !== 'currency' ,
468481 } ) } >
469482
470483 < span part ="prefix " class ="input__prefix ">
You can’t perform that action at this time.
0 commit comments