0

I am trying to complete challenge 2 of Lightning Framework specialist.

The form’s controller checks whether the event.force:createRecord event is supported by a standalone app and either shows or hides the New button according to best practices.

I am using the followign piece of code for the above requirement.

In Lightning Component

<aura:attribute name="isNewEnabled" type="Boolean"/>

<aura:if isTrue = "{!v.isNewEnabled}">
            <lightning:layoutItem flexibility="grow">
                <lightning:button label="New" class="slds-button slds-button_neutral"/>
            </lightning:layoutItem>
        </aura:if>

In Lightning Component Js Controller

var isEnabled = $A.get("e.force:createRecord");
        console.log('**8&&&&'+$A.get('e.force:createRecord'));
        if(isEnabled){
            component.set(isNewEnabled, true);
        }

However, the console is printing the value as undefined as a result of which the button is not being rendered in my desktop.

Is this the correct way to implement the above?

3
  • Where are you testing the same in Lightning Application OR in the tab?
    – Amit Singh
    Commented Jul 17, 2018 at 10:13
  • I am testing in a lightning application.
    – Madhurima
    Commented Jul 17, 2018 at 10:28
  • In Lightning Application, you will not get the Event and this is the reason that you are getting undefined in the Debug. test the same in Lightning using the tab as described in requirement.
    – Amit Singh
    Commented Jul 17, 2018 at 10:30

2 Answers 2

3

Yes. You are doing it in the correct way. Are you testing in Lightning Application as In Lightning Application, you will not get the Event and this is the reason that you are getting undefined in the console.? test the same in Lightning using the tab as described in requirement.

0
0

I think when you are setting the attribute value you need to provide the value provider i.e.

component.set("v.isNewEnabled", true);

You must log in to answer this question.

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