8

NOTE: THE QUESTION DISCUSSES ONE FEATURE THAT IS IN WINTER '25

Today one of the Sandbox I am working on got updated to Winter '25. With these come some changes to LWC components. The one I just noticed is that for lightning-input for type='date', there's now a new formatter that displays below the field, which is really useful.

But, is there a way to remove this formatter?

<lightning-input type="date" variant="label-stacked" label="Quote due date"></lightning-input>

enter image description here

Edit: this is the loading screen;
enter image description here

Winter '25 Release Information: https://help.salesforce.com/s/articleView?id=release-notes.rn_lc_base_component_accessibility.htm&release=252&type=5

Quote from documentation:

lightning-input component now displays the expected date format below the text input field for input types date and datetime

11
  • Preview for Winter '25 starts September 8; Spring '25 comes later. Version incl. patch level here. You don't have any custom validity reporting for this lightning input in place, by any chance? Commented Aug 31 at 7:54
  • @FelixvanHove I think you are right, this might be Winter'25 release preview. I am seeing zebra and astro sliding on ski during loading windows within Salesforce and yes I don't have any custom validity reporting for this lightning-input, basically, just that tag with type ='date' showing this formatting under the field. Also this is not reflected in the Salesforce component library for lightning-input of type date as well. (developer.salesforce.com/docs/component-library/bundle/…). I just noticed this today, the preview might have been loaded to sandbox today?
    – prem22
    Commented Aug 31 at 9:18
  • @FelixvanHove you are right, this is related to Winter'25 release, I have added more information to the question above and the official documentation for the Winter'25 release for Lightning Web Component changed :)
    – prem22
    Commented Aug 31 at 10:37
  • I didn't believe you're looking at a a preview Sandbox, because the timelines stated in the page I referred to in my earlier comment are incorrect. My apologies! Unfortunately Salesforce does not yet allow me to create a scratch org using the preview release. Maybe there's a styling hook that you can utilize? Commented Aug 31 at 10:46
  • @FelixvanHove I see, no apologies needed, :). Yes, that is what I was finding for if there are any styling hooks available (haven't checked this), but I was checking the documentation for lightning-input, if they added new attributes to hide this
    – prem22
    Commented Sep 3 at 3:37

4 Answers 4

7

enter image description here

You can get rid of the expected date format under the DateTime/Date fields by overriding the CSS using the LoadStyle method as explained below:

Step 1: Upload Static Resource

  1. Create a RemoveDateFormatStyle.css file using Notepad++
  2. RemoveDateFormatStyle.css should contain the below CSS:
        .date-format-hide .slds-form-element__help{
            display: none;
        }
        .date-format-hide .slds-show{
            display:block;
        }
  1. Upload it as a Static Resource in SF and make it public.

Step 2: Add a class to your LWC Input Date Element

  1. Add a class to your input element of type date which should hide this expected date format.

<lightning:input class="date-format-hide" type="date" name="input1" label="Enter a date" />

Step 3: LWC LoadStyle

  1. In your JS file of your LWC component, import the below two lines:

    import { loadStyle } from 'lightning/platformResourceLoader';
    import styles from '@salesforce/resourceUrl/RemoveDateFormatStyle';
  1. Use RenderedCallBack to load your customized style into the DOM.

    renderedCallback(){
         Promise.all([
             loadStyle(this, styles) //specified filename
         ]).then(() => {
             window.console.log('Files loaded.');
         }).catch(error => {
             window.console.log("Error " + error.body.message);
         });
     }

Hope this helps!!

Final Result: enter image description here

2
  • 1
    Thank you very much for your answer and a well formatted and written one too! :) I have not tested this out yet, but seems like a good workaround while we wait for official release, if there are any attribute to pass in to the lightning-input tag to hide this formatter
    – prem22
    Commented Sep 4 at 7:24
  • 1
    Will wait for one more release before implementing this. Hoping SF provides a better way to handle the tag by then Commented Sep 12 at 3:40
2

Use the below in rendered callback to remove that label,

html-

<lightning-input required type="date" label="Date of Birth" data-field="Date_of_Birth__c" value={value}></lightning-input>

js-

loaded = false
renderedCallback() {
 if(!this.loaded) {
  let style = document.createElement('style')
  style.innerText = 'div[class=slds-form-element__help]{display:none;}'
  this.template.querySelector("lightning-input[data-field='Date_of_Birth__c']").appendChild(style)
  this.loaded = true
 }
}
1
  • This will work but the only problem is, it will hide the other custom validation messages that comes with the input element along with hiding the date format. So this is not suggested. The same slds-form-element__help is used to display validation messages of the input element.
    – Jayanth G
    Commented Oct 2 at 0:51
0

using a selector like this in your css will still allow regular errors to be displayed as the data-date-format attribute gets replaced when an error needs to be displayed.

[data-date-format].slds-form-element__help {
    display: none;
}
2
  • 1
    Unfortunately you'd be adding css to your custom lwc, not the lightning-input web component that the data attribute is in so this won't work. I did test it just in case, no dice. Commented Sep 6 at 6:19
  • It will work if you create a css static resource and use loadStyle in your component.
    – Jolly
    Commented Sep 10 at 5:13
0

Following on Oliver's example, this is a bit more robust.

    export default class Foo {
      @api loaded = false;
      // In my case I added data-ui='Date Picker' to my date picker elements
      @api selector = "data-YOURSELECTORNAME='YOUR SELECTOR VALUE'":;
          
      async renderedCallback() {
        if (!this.loaded) {
          // This gets rid of date format below the field
          let style = document.createElement("style");
          style.innerText = "div[class=slds-form-element__help]{display:none;}";
          try {
            this.template.querySelector("lightning-input[" + selector + "]").appendChild(style);
            this.loaded = true;
          } catch (ex) {
             // renderedCallback() happens multiple times and before the inputs are rendered so we can eat this
          }
        }
      }

You must log in to answer this question.

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