I want to have a button on my LWC to validate the values of my lightning-input-field's and lightning-input fields.
I am trying to return the value of my lightning-input-fields based on the field-name attribute, but receive the error - [Cannot read properties of null (reading 'value')] (Test 1). I am able to retrieve the values if I use a class (Test 2).
JS
handleValidate(event){
const test1 = this.template.querySelector('[field-name="CurrentBaseLow__c"]').value;
console.log('Test 1 = ' + test1);
const test2 = this.template.querySelector('.test').value;
console.log('Test 2 = ' + test2);
}
HTML
<template>
<lightning-record-edit-form record-id={recordId} object-api-name="Match__c" onerror={handleError}>
<lightning-input-field field-name="CurrentBaseLow__c" disabled={fieldDisabled} onchange={handleChange} class="validate test"></lightning-input-field>
<lightning-input type="number" name="currentBaseHigh" label="Base High (K)" value={currentBaseHigh} onchange={handleChange}></lightning-input>
</lightning-record-edit-form>
<lightning-button variant="brand" label="Validate" onclick={handleValidate} class="slds-p-left_x-small"></lightning-button>
</template>