• Aman Agarwal 1
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I just started playing with Lightning and have created controller and cmp. Intended behavior:
  1. User enters text in 'Find Travelingspoon' field, click Submit, it displays text 'Hi, [text]' - this part works fine.
  2. When user clicks 'Clear  button on Salesforce1, it clears whatever text is in the 'Find Traveling Spoon' text box, but it's not clearing out the text, the text stays in the box.
Please advise what's wrong. Thanks.

Here's my component code:
<aura:component implements="force:appHostable" access="global">
    
    <ui:inputText aura:id="name" label="Find TravelingSpoon:"/>
    
    <ui:button aura:id="button" buttonTitle="Submit Input" class="button" label="Submit" press="{!c.getInput}"/>
    <ui:outputText aura:id="outName" value="" class="text"/>

    <ui:button aura:id="button" buttonTitle="Clear the field" class="button" label="Clear" press="{!c.clearName}"/>    
    
</aura:component>

Here's my controller code:
({
    getInput : function(cmp, evt) {
        var myName = cmp.find("name").get("v.value");
        var myText = cmp.find("outName");
        var greet = "Hi, " + myName;
        myText.set("v.value", greet);
        cmp.set("v.value", []);
    }
})

({
    clearName : function(cmp, evt) {
    cmp.find("outName").set("v.value", "");
}

    }
    )
I'm building an app with basic form using Lightning, the Submit button works, but the Clear button doesn't work - it's supposed to clear the field after user enters name and hit submit. Please advise what I missed. thanks.

HelloWorld.cmp:
<aura:component implements="force:appHostable" access="global">
    
    <ui:inputText aura:id="name" label="Find My TravelingSpoon:"/>
    <ui:button aura:id="button" buttonTitle="Click to see what you put into the field" class="button" label="Submit" press="{!c.getInput}"/>
    <ui:outputText aura:id="outName" value="" class="text"/>
    <ui:button aura:id="button" buttonTitle="Clear the field" class="button" label="Clear" press="{!c.clearName}"/>    
   
</aura:component>

HelloWorldController.js:
({
    getInput : function(cmp, evt) {
        var myName = cmp.find("name").get("v.value");
        var myText = cmp.find("outName");
        var greet = "Hi, " + myName;
        myText.set("v.value", greet);
    }
 clearName : function(cmp, evt) {
    var myName v= cmp.set("outName", []);
}    
})

User-added image