1

Hi how can show the value of the field in the LWC toast message which contains the date. I am trying to show but getting the value as undefined.

JS code:

@track MDate ===2020-07-15
@track StDate === 2019-07-15


showToast(message) {
        const event = new ShowToastEvent({
            title: 'Toast message',
            message: message,
            variant: 'error',
            mode: 'dismissable'
        });
        this.dispatchEvent(event);
    }
    
    
this.showToast("Wrong Date selected in the Start Date It Should be between ");
// I want to pass the StDate and MDate as a argument in the message so that it can be displayed as a toast message on UI

1 Answer 1

1

You need to convert your date to string & append it with your error message -

this.showToast("Wrong Date selected in the Start Date It Should be between " + this.MDate.toString() + "-" + this.StDate.toString());
1
  • Please note that toString() displays the date in full ISO format. Also, you are missing this while referring to the date variables. MDate.toString() should be this.MDate.toString() Jul 16, 2020 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .