I have a child component, in which I'm using lightning-record-edit-form and in that I have lightning-input-field where some of them are required.
Now when I'm submitting the form from parent I want to check all required field, without hardcoding them.
Child Component HTML:
<template>
<lightning-record-edit-form object-api-name="SalesRequest__c">
<!-- Account Creation Section -->
<div if:true={createAccount} class="slds-m-top_medium">
<div class="slds-grid slds-gutters">
<div class="slds-col slds-size_1-of-2">
<lightning-input-field field-name="Street__c" data-name="Street__c" required="true"></lightning-input-field>
<lightning-input-field field-name="City__c" data-name="City__c" required="true"></lightning-input-field>
<lightning-input-field field-name="State__c" data-name="State__c" required="true"></lightning-input-field>
</div>
<div class="slds-col slds-size_1-of-2">
<lightning-input-field field-name="Is_owner__c" data-name="Is_government_owner__c" required="true"></lightning-input-field>
<lightning-input-field field-name="ZipCode__c" data-name="ZipCode__c" required="true"></lightning-input-field>
<lightning-input-field field-name="Country__c" data-name="Country__c" required="true"></lightning-input-field>
</div>
</div>
</div>
</lightning-record-edit-form>
</template>
Parent Component HTML:
<template>
<c-sales-request request-type={reqType}></c-sales-request>
</template>
Parent Component JS:
const childcomp = this.template.querySelector('c-sales-request');
console.log('>>> childcomp... '+JSON.stringify(childcomp));
if(childcomp != undefined){
let childfields = childcomp.getRecordEditFormData();
console.log('>>> childfields... '+JSON.stringify(childfields));
if( childfields != undefined){
for (const [key, value] of Object.entries(childfields)) {
console.log('>>> key... '+key);
console.log('>>> value... '+value);
if(key == 'Is_owner__c' && value == null){ // here I'm hardcoding required value
this.isRquiredCheck = true;
}else if(key == 'Is_owner__c' && value != null){
this.isRquiredCheck = false;
}
fields[key] = value;
}
}
}
So instead of hardcoding all required field name, I want to know if there is a generic way to check if all required fields are filled or not