Can I use lightning-inputfield and lightning-input in the same form and submit? In below code, phone field value is not saved in the lead record. not just the phone I have some more fields that I need to set values before saving this record along with phone. Any inputs please?
<lightning-record-edit-form object-api-name="Lead">
<lightning-input label="Phone" class="inputCmp" field-name="Phone" value={leadRecord.Phone} pattern="^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$" message-when-pattern-mismatch="Please enter a valid phone number" onchange={handleChange} maxlength="10" onfocusout= "{validate}" > </lightning-input>
<lightning-input-field field-name="Email" value={leadRecord.Email} onchange={handleChange} required> </lightning-input-field>
<lightning-button
onclick={handleSuccess}
label="Create Lead"
></lightning-button>
</lightning-record-edit-form>
handleChange(event) {
// alert(event.target.value);
this.leadRecord[event.target.name] = event.target.value;
}
handleSuccess(event) {
const fields = this.leadRecord;
console.log(this.leadRecord);
const recordInput = { apiName: LEAD_OBJECT.objectApiName, fields };
alert(recordInput);
createRecord(recordInput)
.then((lead) => {
this.leadId = lead.id;
this.dispatchEvent(
new ShowToastEvent({
title: "Success",
message: "Account created successfully!",
variant: "success"
})
);
this.leadRecord = {};
})
.catch((error) => {
this.dispatchEvent(
new ShowToastEvent({
title: "Error creating record",
message: " ",
variant: "error"
})
);
})
.finally(() => {
});
update:
<lightning-input label="Phone" class="inputCmp" name="Phone" value={leadRecord.Phone} pattern="^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$" message-when-pattern-mismatch="Please enter a valid phone number" onchange={handleChange} maxlength="10" onfocusout= "{validate}" > </lightning-input>
I tired to test adding an alert
alert(this.leadRecord[Phone]);
