0

I am trying to set the actual date (today) as a minimum value to my date picker, using LWC. I can't make it work, as I get a component error message that "today is not defined".

HTML

<template> <lightning-record-edit-form object-api-name="Reservation__c"> <lightning-messages> </lightning-messages> <lightning-input-field field-name="Date__c" type="date" name="Reservation__c" label="Date field" min={today} max="2024-01-01"> </lightning-input-field> <lightning-button class="slds-m-top_small" type="submit" label="Create new"> </lightning-button> </lightning-record-edit-form> </template> 

In the JS file:

@track today; connectedCallback(){ this.today = new Date(); let yyyyMmDd = today.toISOString().slice(0,10); } 

I don' know actually what to or how to set the today and use it as the min value (if it is possible).

2

1 Answer 1

4

Based on your answer above it looks the min property even if not documented should be in the format YYYY-MM-DD.

Try something like that:

today; // track is not needed for primitive types connectedCallback(){ this.today = new Date().toISOString().slice(0,10); } 

If will not work, add also if:true to HTML so element will render when today will be set.

<lightning-input-field if:true={today} field-name="Date__c" type="date" name="Reservation__c" label="Date field" min={today} max="2024-01-01"> </lightning-input-field> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.