I have a lightning-input of type date. When I enter an invalid value in this field, there is a validation displayed 'Your entry does not match the allowed format MMM d, yyyy.' I want to clear this message along with the value in the input field on click of the clear button. I have tried using below approach, but it doesnt clear the value:


 this.template.querySelectorAll('.DateFilters').forEach(element => {
        element.value = '';


<lightning-input class="DateFilters slds-size_1-of-5 slds-m-left_x-small slds-m-top_x-small" 
type="date" label="Created Date" data-id="CreatedDate" data-item="from"></lightning-input> 

<lightning-button-group class="slds-float_left">
        <button class="wu btn btn-yellow slds-m-left_xx-small" onclick={clearAll}>Clear</button>
  • Hi Krish, your code works fine in the LWC playground (developer.salesforce.com/docs/component-library/tools/…). Try comparing this carefully with your actual code and see if there might not be something else amiss. Also -- you shouldn't need to use setCustomValidity('') if you never set it to a nonblank value in the first place. – Matthew Souther Jul 6 '20 at 20:33
  • @MatthewSouther This same code works in one of my dev sandboxes but fails in other sandboxes. What could be the reason? – Krish Jul 7 '20 at 6:00
  • Interesting. Have you noted whether the sandboxes that are failing are on Summer '20 preview instances? That's the only reason I can think of that something would break in one environment and not another. – Matthew Souther Jul 7 '20 at 16:20

Your Answer

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

Browse other questions tagged or ask your own question.