1

i am encountering error with below

Var req_val= cmp.find("required").get("v.value");

earlier it was working fine, now it is not working getting

error

Uncaught Action failed: c$my_comp$controller$closeTask [TypeError: Cannot read property 'get' of undefined] 

i am calling this function from Event

closeTask:function(cmp,event,helper){
console.log(cmp.find('required').get('v.value'));// here is the error

var eventId = event.getParam("recordId");

Event is registered in child and handling in parent. it consist of recordId.

required attribute is in parent. cant we get this attribute value in parent am getting as undefined.

please suggest.

6
  • Please add some more code May 20, 2016 at 11:51
  • Please if you could share sample code snippets it's easier to assist you May 20, 2016 at 12:07
  • Hi Mohit, i added little bit code and explained how am using it.
    – Raj_SFDC
    May 20, 2016 at 12:13
  • Find is used on DOM aura Id . May 20, 2016 at 12:15
  • Cant we get the aura:id or aura:attribute value of parent in this scenario. i am still getting undefined event with attribute cmp.get("parentAttribute"); or cmp.find("prntDom").get("v.value");
    – Raj_SFDC
    May 20, 2016 at 12:27

2 Answers 2

2

create an aura:Attribute in your event, which you should pass while invoking the event

Aura attribute in event -

<aura:attribute name="sObjectId" type="Id" required="true" description="The Id of the selected SObject." />

While invoking event - var updateEvent = cmp.getEvent("eventName");

// Populate the event with the selected Object Id
updateEvent.setParams({
    "sObjectId" : value
}); 

In the event handler's action write following -

// Get the Id from the Event
var accountId = event.getParam("sObjectId");

Hope this helps :)

2
  • The issue is user getting undefined which he is not expecting and expecting a value .Its not about how to avoid error here May 20, 2016 at 12:29
  • Thank you sneha, i was good with that , but had problem with parent tag DOM ID , am getting undefined if i use that DOM ID in cmp.find('auraId');
    – Raj_SFDC
    May 20, 2016 at 14:57
1

Find function is always used with aura local Id .Please check how to use it

While get function is used to get the attribute value

Try this

cmp.get(""required"");
1
  • Hi Mohit, as of now am not able to find the value with DOM id (this tag value is attribute value that am changing dynamically) still undefined but i am getting the value based on attribute cmp.get("v.required_attr"); . Thank you for suggestion. Apologies not pasting code here as am not working own dev org.
    – Raj_SFDC
    May 20, 2016 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.