0

I have LWC form page build on Business hours, on which I have prepopulated the last record that I have saved of the type dateTime in the input field. When I click on save button I get the bellow standard validation issue "Your entry does not match the allowed format h:mm a."

HTML Code

<lightning-input-field field-name="SundayStartTime" value={sundaystartTime}></lightning-input-field>

Js code

 this.sundaystartTime =new Intl.DateTimeFormat([],{ hour:"numeric", minute: "numeric", hour12: true,timeZone: "UTC"}).format(result[0].SundayStartTime);

enter image description here

2
  • Can you please tell what is the field type of SundayStartTime in Object and also the use case Nov 10, 2022 at 10:13
  • It of type time in milliseconds , like this 90000 Nov 19, 2022 at 3:39

2 Answers 2

1

You need to pass the time in ISO 8601 format only. For example:

10:30:26+05:30 // hh:mm:ss+HH:MM where +HH:MM is a time zone offset
10:30:26 // without timezone
10:20 // without seconds

But your code is passing like this 10:30 AM

So if you pass the time in 24 hours format then it will work fine!

Note: The below code is only required if result[0].SundayStartTime is full date value.

new Intl.DateTimeFormat('en-GB', {hour:"numeric", minute: "numeric", timeZone: "UTC"}).format(result[0].SundayStartTime);
1
  • 1
    My issue got solve by using the below code snip: new Intl.DateTimeFormat([],{ hour:"numeric", minute: "numeric", second: "numeric",hourCycle: "h23",timeZone: "UTC",fractionalSecondDigits: 3}).format(result[0].SundayStartTime); Nov 19, 2022 at 3:40
0

Use below to format the data and display in lwc:

  <lightning-input type="date" class="startDate" value={selectedStartDate}  date-style="short"
                                    name="startDate" label="Start Date" onchange={handleInputChangeValidation} onclick={handleInputChangeValidation} disabled={isEnabledChecked}
                                    required></lightning-input>

In JS:

  let startDate='2023-07-20T00:00:00.000Z' //Say this format is coming from apex
  this.selectedStartDate=new Date(startDate).toISOString();

You must log in to answer this question.

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