0

I'm trying to take the boolean value of a checkbox field and load it into a toggle via the doInit but it's not working. Am I doing something wrong?

When I debug it says osiValue is undefined

Happy to provide more code from the cmp if you need. Thanks

Comp:

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<lightning:inputField fieldName="Override_Standard_Interest__c" label="Override_Standard_Interest__c" name="toggle" aura:id="osi"/> 

<lightning:input type="toggle" checked="{!v.overrideStandardInterest}" label="" variant="label-hidden" name="toggle" onchange="{!c.jamie}"/> 

Controller:

doInit : function (component, event, helper) {          
        var osiValue = component.find("osi").get("v.value");                           
        component.set('v.overrideStandardInterest', osiValue);
    },

1 Answer 1

1

It wouldn't work, because lightning:inputField values won't be loaded until sometime after aura:valueInit. Records are always loaded asynchronously, so you can guarantee that this value won't be available until after doInit has been called. You'll need to wait for an appropriate event that tells you the data has been loaded, such as the onload event of lightning:recordEditForm, or recordUpdated in the force:recordData component.

1
  • Thanks a million sfdcfox! ..I have switched it over to onload and it's working a treat. Best regards
    – Jay
    Commented Apr 22, 2020 at 16:02

You must log in to answer this question.

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