You need to sign in to do that
Don't have an account?
MRITYUNJAY PATEL 3
How to clear the input filed value after clicking the button
Hi Everyone,
i m trying to clear the input field value after clicking the clear button in my code.
//This is my code aura code
<aura:component controller="AuraApex" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="FirstName" type="String" />
<aura:attribute name="LastName" type="String" />
<aura:attribute name="AccountList" type="List" />
<aura:attribute name="NewAccount" type="String" />
<div>
<lightning:input type="String" label="FirstName" aura:id="firstn" value="{!v.FirstName}" required="true"/>
<lightning:input type="String" label="LastName" aura:id="lastn" value="{!v.LastName}" required="true" />
<div>
<lightning:select name="select1" label="List Of Existing Account" aura:id="AccountId" required="false" >
<option value="" label="--None--">
</option>
<aura:iteration items="{!v.AccountList}" var="ac" >
<option value="{!ac.Id}" label="{!ac.Name}" />
</aura:iteration>
</lightning:select>
</div>
<div>
<lightning:select name="select2" label="List Of Industry" aura:id="IndId" required="false" >
<option value="" label="--None--">
</option>
<aura:iteration items="{!v.AccountList}" var="in" >
<option value="{!in.Id}" label="{!in.Industry}" />
</aura:iteration>
</lightning:select>
</div>
<br/>
<br/>
<div class="slds-form-element">
<label class="slds-checkbox_toggle slds-grid">
<span class="slds-form-element__label slds-m-bottom_none">New Account Create</span>
<ui:inputCheckbox change="{!c.selectChange}"/>
<span id="toggle-desc" class="slds-checkbox_faux_container" aria-live="assertive">
<span class="slds-checkbox_faux"></span>
<span class="slds-checkbox_on">New</span>
<span class="slds-checkbox_off">Old</span>
</span>
</label>
</div>
<!--PART 2 : create a Div with slds-hide class, control by toggle checkbox-->
<div aura:id="DivID" class="slds-hide">
<lightning:input type="String" label="Account Name" aura:id="AccountId" value="{!v.NewAccount}"/>
</div>
<br/>
<lightning:button variant="brand" label="Submit" title="Brand action" onclick="{! c.handleClick }" />
<lightning:button variant="brand" label="clear" title="Brand action" onclick="{! c.clear }" />
</div>
</aura:component>
i m trying to clear the input field value after clicking the clear button in my code.
//This is my code aura code
<aura:component controller="AuraApex" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="FirstName" type="String" />
<aura:attribute name="LastName" type="String" />
<aura:attribute name="AccountList" type="List" />
<aura:attribute name="NewAccount" type="String" />
<div>
<lightning:input type="String" label="FirstName" aura:id="firstn" value="{!v.FirstName}" required="true"/>
<lightning:input type="String" label="LastName" aura:id="lastn" value="{!v.LastName}" required="true" />
<div>
<lightning:select name="select1" label="List Of Existing Account" aura:id="AccountId" required="false" >
<option value="" label="--None--">
</option>
<aura:iteration items="{!v.AccountList}" var="ac" >
<option value="{!ac.Id}" label="{!ac.Name}" />
</aura:iteration>
</lightning:select>
</div>
<div>
<lightning:select name="select2" label="List Of Industry" aura:id="IndId" required="false" >
<option value="" label="--None--">
</option>
<aura:iteration items="{!v.AccountList}" var="in" >
<option value="{!in.Id}" label="{!in.Industry}" />
</aura:iteration>
</lightning:select>
</div>
<br/>
<br/>
<div class="slds-form-element">
<label class="slds-checkbox_toggle slds-grid">
<span class="slds-form-element__label slds-m-bottom_none">New Account Create</span>
<ui:inputCheckbox change="{!c.selectChange}"/>
<span id="toggle-desc" class="slds-checkbox_faux_container" aria-live="assertive">
<span class="slds-checkbox_faux"></span>
<span class="slds-checkbox_on">New</span>
<span class="slds-checkbox_off">Old</span>
</span>
</label>
</div>
<!--PART 2 : create a Div with slds-hide class, control by toggle checkbox-->
<div aura:id="DivID" class="slds-hide">
<lightning:input type="String" label="Account Name" aura:id="AccountId" value="{!v.NewAccount}"/>
</div>
<br/>
<lightning:button variant="brand" label="Submit" title="Brand action" onclick="{! c.handleClick }" />
<lightning:button variant="brand" label="clear" title="Brand action" onclick="{! c.clear }" />
</div>
</aura:component>
Hi,
Please find the solution.
No need to use clear button as with the help of "Submit" you can also clear the field.
First, you get the fields then assign a null value.
Please mark it as the Best Answer if it helps you.
Thank You
All Answers
Try Below Code JS Please Mark It As Best Answer If It Helps
Thank You!
Hi,
Please find the solution.
No need to use clear button as with the help of "Submit" you can also clear the field.
First, you get the fields then assign a null value.
Please mark it as the Best Answer if it helps you.
Thank You