You need to sign in to do that
Don't have an account?

Lightning: clear button not clearing text field
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", []);
}
})

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", []);
}
})
You should do something more plain like: and
Or simply:
({
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", "");
}
}
)
For Example: This was the id for my components input field : "SearchManager_typeaheadlookup" And now on the controller use the following code to set the value to null.
Your set value thing worked for me, thank you. Not sure why it didnt work for you.
Only difference - i was resetting a lightning:input field.