0

I'm using the code below to display an input field of DateTime data type.

<lightning-record-edit-form object-api-name="Contact" onsubmit={handleSubmit}>
<lightning-input-field field-name="Created_DateTime__c" ></lightning-input-field>
<lightning-button type="submit" label="Save" variant="brand"></lightning-button>
</lightning-record-edit-form>

Here Created_DateTime__c is a DateTime custom field on Contact object. When I tried to save it:

Image

"Error: Invalid date/time: 2025-11-03T09:15:00.000Z"

As it was a standard object & record edit form, I couldn't handle it in a customized way. Can anyone help with this?

1 Answer 1

1

Based on the error message Error saving Probing Question, this looks more like a custom error thrown by a validation rule, Flow/Apex logic, rather than an issue with the lightning-record-edit-form itself.

If you are looking for customizing the lightning-record-edit-form behaviors you can use this as reference Overriding Default Behaviors :

To customize the behavior of your form when it loads or when data is submitted, use the onload and onsubmit attributes to specify event handlers. If you capture the submit event and submit the form programmatically, use event.preventDefault() to cancel the default behavior of the event. This prevents a duplicate form submission.

Errors are automatically handled. To customize the behavior of the form when it encounters an error on submission or when data is submitted successfully, use the onerror and onsuccess attributes to specify event handlers.

Here are some example event handlers for onsubmit and onsuccess.

handleSubmit(event){
   event.preventDefault();       // stop the form from submitting
   const fields = event.detail.fields;
   fields.Street = '32 Prince Street';
   this.template.querySelector('lightning-record-edit-form').submit(fields);
}
handleSucess(event){
   const updatedRecord = event.detail.id;
   console.log('onsuccess: ', updatedRecord);
}

To see all the response data:

handleSuccess(event){
    const payload = event.detail;
    console.log(JSON.stringify(payload));
}

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.