0

I am trying to create a button which will update a field value to null (RESET it). However, it's not working and not even giving any error. So when I click on the button, nothing happens.

lc.cmp:

<aura:attribute name="myObj" type="Account" default="{'SObject':'Account'}"/>
<lightning:input type="text" name="accountPhn" label="Enter Account Phone" value="{!v.myObj.Name}"/>
<lightning:button label="Reset" onclick="{!c.resetMe}"/>

lc.js:

resetMe : function(component, event, helper) {
        //alert("Called");
        component.set("v.accountPhn","");
    }

Appreciate help around this.

2 Answers 2

0

Please change 2nd line with below code. It will work.

    <aura:attribute name="accountPhn" type="String" default="{!v.myObj.Name}"/>
3
  • Hello Dhanik, I need input text box only... hence need to nulify those itself... hope you understand
    – Varun SFDC
    May 3, 2019 at 9:51
  • Please check with this <aura:attribute name="accountPhn" type="String" default="{!v.myObj.Name}"/> <lightning:input type="text" name="text" label="Enter Account Phone" value="{!v.accountPhn}"/> May 3, 2019 at 12:15
  • Worked great... thanks Dhanik
    – Varun SFDC
    May 6, 2019 at 11:22
0

Component.get() and Component.set() works on the attributes defined. Update your component with below, it should be fine.

<aura:attribute name="accountPhn" type="String"/>
<lightning:input type="text" name="accountPh" label="Enter Account Phone" value=" 
{!v.accountPhn}"/>
<lightning:button label="Reset" onclick="{!c.resetMe}"/>

Read more about Component.get() and Component.set()

2
  • I tried... still doesn;t work, same thing, nothing happens... Does below have any significance: ``` <aura:attribute name="accountPhn" type="String"/> <lightning:input type="text" name="accountPh" label="Enter Account Phone" value=" {!v.accountPhn}"/> ``` as I want to nulify the lightning:input type="text"
    – Varun SFDC
    May 3, 2019 at 9:49
  • You can try printing the values using console.log and check the values before it is set to blank , and after it is set to blank and check its not printing undefined. You need to tie the value of <lightning:input> to an attribute of the component and manipulate it using component.set() May 3, 2019 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .