You need to sign in to do that
Don't have an account?
Vinay vinay
The controller action marks the item attribute as packed, updates the item value provider and disables the button.
The controller action marks the item attribute as packed, updates the item value provider and disables the button is the task given in Trail head.
I have written the below controller to perform the action:
({
packItem : function(component, event, helper) {
event.getSource().set('v.disabled',true);
component.set('v.item.Packed__c',true);
}
})
This is setting the Packed__c to true but I am not passing the challenge.
but when I googled, below code was suggested:
({
packItem : function(component, event, helper) {
event.getSource().set('v.disabled',true);
var a = component.get("v.item",true);
a.Packed__c = true;
component.set("v.item",a);
}
})
But this code is not setting Packed__c to true. Please let me know the difference between two controller.
Trail head challenge:
https://trailhead.salesforce.com/lex_dev_lc_basics/lex_dev_lc_basics_controllers
I have written the below controller to perform the action:
({
packItem : function(component, event, helper) {
event.getSource().set('v.disabled',true);
component.set('v.item.Packed__c',true);
}
})
This is setting the Packed__c to true but I am not passing the challenge.
but when I googled, below code was suggested:
({
packItem : function(component, event, helper) {
event.getSource().set('v.disabled',true);
var a = component.get("v.item",true);
a.Packed__c = true;
component.set("v.item",a);
}
})
But this code is not setting Packed__c to true. Please let me know the difference between two controller.
Trail head challenge:
https://trailhead.salesforce.com/lex_dev_lc_basics/lex_dev_lc_basics_controllers
Please check with below thread from forums community for similar issue with possible workarounds.
- https://developer.salesforce.com/forums/?id=906F0000000kD4mIAE
Hope this helps.Best Regards,
Nagendra.P
My question is:
how
var a = component.get("v.item",true);
a.Packed__c = true;
is different from
component.set('v.item.Packed__c',true);
That is not explained in above link which you had provided.
Regards
Vinay Tej
Please refer the below link for the above explanantion as:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_attr_values.htm
Hope this will clear the difference between the two.
Please mark this as best answer if your query is resolved.
Thanks,
Mohammad Anis
You can use "set" as:
packItem : function(component, event, helper) {
event.getSource().set('v.disabled',true);
component.set("v.item.Packed__c", true);}
I have tested the same in my Dev. Org. and It is working.
Please mark this as best answer if your query is resolved.
Thanks,
Mohammad Anis
----------------------------COMPONENT---------------------------
<aura:component >
<aura:attribute name="item" type="Camping_Item__c" required="true" default="{Name:'Tent', Price__c:100, Quantity__c:1, Packed__c:true}"/>
<p>{!v.item.Name}</p>
<lightning:formattedNumber value="{!v.item.Price__c}" style="currency" currencyCode="USD"/>
<lightning:formattedNumber value="{!v.item.Quantity__c}" maximumFractionDigits="0"/>
<lightning:input type="toggle" label="Packed?" name="packed" checked="{!v.item.Packed__c}"/>
<lightning:button label="Packed!" onclick="{!c.packItem}"/>
</aura:component>
----------------------------CONTROLLER---------------------------
({
packItem : function(component, event, helper) {
component.set("v.item.Packed__c", true);
event.getSource().set('v.disabled',true);
}
})