I want to get field-name(label) and field-value of each field for validation as shown below. Is there any way to do it in LWC?
sampleRecordViewForm.html
<template>
<lightning-record-view-form record-id="XXXXXXXXXXXXXXX"
object-api-name="My_Contact__c">
<div class="slds-box">
<lightning-output-field field-name="Name"></lightning-output-field>
<lightning-output-field field-name="Email__c"></lightning-output-field>
</div>
<lightning-button onclick={handleDetailsClick} label="Get Field Details"></lightning-button>
</lightning-record-view-form>
</template>
sampleRecordViewForm.js
import { LightningElement} from 'lwc';
export default class SampleRecordViewForm extends LightningElement {
handleDetailsClick() {
const outputFields = this.template.querySelectorAll('lightning-output-field');
if (outputFields) {
outputFields.forEach(field => {
// eslint-disable-next-line no-console
console.log('field', field);
});
}
}
}
I want to do processing on these fields so I want field label and field values.