<lightning-input-field field-name="Date_of_Joining__c" onchange={handleFieldChange}> </lightning-input-field> this is tag where i want to put min and max value for my date


You cannot set min and max for lightning-input-field like that of lightning-input. You should implement the logic in change handler.

As you want to validate dates, you will require to create javasript date object and compare it with selected date.

import { LightningElement, wire, api, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent'

export default class Poc extends LightningElement {

    handleFieldChange(event) {
        let selected = new Date(event.target.value);
        let max = new Date(2019, 7, 30);  // 30 Aug 2019 (month is 0 index based)
        let min = new Date(2019, 7, 1); // 1 Aug 2019
        if (selected > max || selected < min)
            this.dispatchEvent(new ShowToastEvent({
                title: 'Enter valid date',
                variant: 'error',
                message: `Date should be between ${min.toDateString()} and ${max.toDateString()}`,
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.