In LWC, there are multiple input fields but input types are combo box & text, and a few of them are required.
Below is the html code
<lightning-combobox
class ='validateClass'
data-fieldname={fieldDetail.fieldAPIName}
data-objname={secVal.objectName}
name="Picklist"
label={fieldDetail.fieldLabel}
value={pickListOptionSelection}
placeholder="Select"
options={fieldDetail.pickListOptions}
onchange={handleChangePickList}
required = {fieldDetail.isRequired}>
</lightning-combobox>
<lightning-input class ='validateClass'
data-objname={secVal.objectName}
data-fieldname={fieldDetail.fieldAPIName}
value={inputData}
type={fieldDetail.fieldType}
variant="standard"
name={fieldDetail.fieldAPIName}
required = {fieldDetail.isRequired}
label={fieldDetail.fieldLabel}
placeholder="type here..."
onblur={handleInputBlur}>
</lightning-input>
On clicking on the Cancel button we have to reset the form. Below is the code that is written on cancel button click.
//method will call on cancel button click
handleCancelClick(){
this.isDatatableVisible = false;
this.template.querySelectorAll('.validateClass').forEach(each => {
each.value = '';
if(each.required){
each.classList?.remove('slds-has-error');
each.className?.replace('slds-has-error');
}
});
}
I've attached a picture of the issue.
I've tried using below code but same issue.
this.template.querySelectorAll('.validateClass').forEach(each => {
each.reset();
});
setCustomValidity('')
setCustomValidity('')
but still same issue.