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}"/>
2
  • Hello Dhanik, I need input text box only... hence need to nulify those itself... hope you understand Commented 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}"/> Commented May 3, 2019 at 12:15
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" Commented 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() Commented May 3, 2019 at 10:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.