1

I am taking record id and object name as input from user

    <aura:attribute name="recordidinput" type="Id" />
    <aura:attribute name="objectname" type="String" />
    
    <lightning:input name="objectdetail" label="Object" value="{!v.objectname }" placeholder="enter the object..."/>
    <lightning:input name="recordiddetail" label="Record ID" value="{!v.recordidinput }"
placeholder="enter the recordId..."/>
    <lightning:button variant="brand" label="Submit" title="Submit" onclick="{!c.handleSubmit}" />


These attributes have to be passed on to a child component as follows :

    <c:displayRecordDetailsLWC recordIdDetail="{!v.recordidinput}" objectName="{!v.objectname}">

The problem is that :

The value should get passed to child component only when submit button is pressed. Right now, the button is useless and due to two-way binding the values are getting updated at every keystroke which is not what I want.

1 Answer 1

2

Don't bind the value, but assign it when you want to update the child object:

<lightning:input aura:id="objectdetail" label="Object" placeholder="enter the object..."/>
<lightning:input aura:id="recordiddetail" label="Record ID" />

...

handleSubmit: function(component, event, helper) {
  let objectdetail = component.find("objectdetail").get("v.value");
  let recordiddetail = component.find("recordiddetail").get("v.value");
  component.set("v.objectname", objectdetail);
  component.set("v.recordidinput", recordiddetail);
}
5
  • Thank you! I wanted to ask if there are any resources that you can suggest to learn how to play around with attributes and methods like this? Jun 28, 2021 at 4:28
  • 1
    @ShreyaPandita There's no "one place" for things like this. A lot of things are possible. setTimeout is a common Aura example, mentioned here in the docs, and you can find other examples out there on the Internet (e.g. doing an API call, loading a file, and other asynchronous tasks). And, of course, feel free to turn here, we love coming up with solutions that aren't in the books.
    – sfdcfox
    Jun 28, 2021 at 4:57
  • 2
    And wherever possible, use an LWC component. Despite binding being slightly more complex to implement, just about everything else is easier / faster (especially calls to the server). Jun 28, 2021 at 5:00
  • 2
    @CasparHarmer Also a good point. LWC has one-way binding, so doing it as in this answer is the natural mode for LWC.
    – sfdcfox
    Jun 28, 2021 at 5:01
  • Nice, I did not know LWC has one-way binding! Will check it out next time My use-case was that I had to call two child components (one aura and one lwc). I used aura as a parent component because I read somewhere we cannot call aura child component from lwc. Jun 28, 2021 at 5:32

You must log in to answer this question.

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