Clear input fields with button
Sat Feb 25 2023 02:49:41 GMT+0000 (Coordinated Universal Time)
Saved by
@gbritgs
#html
#javascript
#HTML#
<lightning-layout-item size="6" >
<lightning-input type="text" onchange={handleInput} maxlength="9" placeholder="Digite o CEP"> </lightning-input>
</lightning-layout-item>
<lightning-layout-item size="12" padding="horizontal-small">
<lightning-input disabled="true" value={obj.logradouro} type="text" placeholder="Rua" data-id="form"> </lightning-input>
</lightning-layout-item>
<lightning-button class="btn" onclick={clearFields} label="Limpar" variant="brand"></lightning-button>
#JS#
clearFields() {
this.template.querySelectorAll('lightning-input').forEach(element => {
element.value = null;
});
// you can also reset one by one by id
// this.template.querySelector('lightning-input[data-id="form"]').value = null;
}
content_copyCOPY
Comments