I'm able to change and show the modified value of date on a lightning-input type="date"
LWC component . My JS code will calculate and show the first date of the month for any date selection of the month using date picker. Perfect. When I change the date again using the date picker FOR THE SAME MONTH, it will not show the first date as value. But using date picker if I pick another month and date it will show the first month, which is good. But again for this month also if I repeat and change date using date picker it will show the selected date only, even though on console.log I can see the value of {startDtToFirstOfMonth}
as the first month always. Very strange. Any clues?
<lightning-input value={startDtToFirstOfMonth} type="date"
name="stDt" label="Enter a date" onchange={handleStDateCahngeEvent}>
</lightning-input>
JS
@track startDt;
@track startDtToFirstOfMonth;
handleStDateCahngeEvent(event){
this.startDt = event.target.value;
this.startDtToFirstOfMonth = this.getFirstDateOfMonth(this.startDt) ;
}
getFirstDateOfMonth(dt){
const regex = /(\-\d\d)$/;
var givenDateConvertedToFirst = dt.replace(regex,'-01');
return givenDateConvertedToFirst ;
}