Skip to content

Commit ef6d0ba

Browse files
committed
add date to accaptable type form min & max
1 parent ec0aed7 commit ef6d0ba

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#changelog
2+
## [3.11.0] - 2023-11-12
3+
### new features
4+
- add Date to valid type for min & max date restriction input
25
## [3.10.0] - 2023-11-12
36
### new features
47
- add placeholder support when input is empty

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,24 @@ by setting value type you can tell component what type of value you provideing t
9999

100100
## min and max date limit
101101

102-
you can set minimum date and maximum date range for your app
102+
you can set minimum date and maximum date range for your date input in 2 way:
103+
104+
1- by html attribute in string format of your value
103105

104106
```html
105107
<jb-date-input label="تاریخ شروع " value="2020-08-10T08:51:23.176Z" min="2020-08-05T08:51:23.176Z" max="2020-08-15T08:51:23.176Z">
106108
</jb-date-input>
109+
```
110+
2- by call `setMinDate` and `setMaxDate` function and providing string or Date format:
111+
112+
```javascript
113+
const today = new Date();
114+
document.querySelector('jb-date-input').setMinDate(today)
115+
const max = new Date('2022-08-15T08:51:23.176Z');
116+
document.querySelector('jb-date-input').setMaxDate(max);
117+
// or string
118+
document.querySelector('jb-date-input').setMinDate('2022-08-15T08:51:23.176Z');
119+
107120
```
108121
## placeholder
109122

lib/JBDateInput.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,34 +413,46 @@ export class JBDateInputWebComponent extends HTMLElement {
413413
this.#setMaxDate(maxDate);
414414
}
415415
}
416-
#setMinDate(dateString: string) {
416+
setMinDate(minDate: string | Date){
417+
this.#setMinDate(minDate);
418+
}
419+
#setMinDate(dateInput: string | Date) {
417420
let minDate: Date | null = null;
418421
//create min date base on input value type
419-
minDate = this.#dateFactory.getDateFromValueDateString(dateString);
422+
if(typeof dateInput == "string"){
423+
minDate = this.#dateFactory.getDateFromValueDateString(dateInput);
424+
}else{
425+
minDate = dateInput;
426+
}
420427
if (minDate) {
421428
this.dateRestrictions.min = minDate;
422429
if (this.elements.calendar.dateRestrictions) {
423430
this.elements.calendar.dateRestrictions.min = minDate;
424431
}
425432
} else {
426-
console.error(`min date ${dateString} is not valid and it will be ignored`, '\n', 'please provide min date in format : ' + this.#dateFactory.valueFormat);
433+
console.error(`min date ${dateInput} is not valid and it will be ignored`, '\n', 'please provide min date in format : ' + this.#dateFactory.valueFormat);
427434
}
428435

429436
}
430-
#setMaxDate(dateString: string) {
437+
setMaxDate(maxDate: string | Date){
438+
this.#setMaxDate(maxDate);
439+
}
440+
#setMaxDate(dateInput: string | Date) {
431441
let maxDate: Date | null = null;
432442
//create max date base on input value type
433-
maxDate = this.#dateFactory.getDateFromValueDateString(dateString);
443+
if(typeof dateInput == "string"){
444+
maxDate = this.#dateFactory.getDateFromValueDateString(dateInput);
445+
}else{
446+
maxDate = dateInput;
447+
}
434448
if (maxDate) {
435449
this.dateRestrictions.max = maxDate;
436450
if (this.elements.calendar.dateRestrictions) {
437451
this.elements.calendar.dateRestrictions.max = maxDate;
438452
}
439453
} else {
440-
console.error(`max date ${dateString} is not valid and it will be ignored`, '\n', 'please provide max date in format : ' + this.#dateFactory.valueFormat);
454+
console.error(`max date ${dateInput} is not valid and it will be ignored`, '\n', 'please provide max date in format : ' + this.#dateFactory.valueFormat);
441455
}
442-
443-
444456
}
445457
inputChar(char: string, pos: number) {
446458
if(pos==4 || pos==7){

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"jalali web-component",
2929
"jalali web component"
3030
],
31-
"version": "3.10.0",
31+
"version": "3.11.0",
3232
"bugs": "https://github.com/javadbat/jb-date-input/issues",
3333
"license": "MIT",
3434
"files": [

0 commit comments

Comments
 (0)