Show checkbox while loading component
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have used Check all / Uncheck All checkboxes function to select group of Values. I used to display some data in aura iteration with checkbox values checked.
If the data row is more than one its working fine suppose if the row count is one im facing error:
"Uncaught Error in $A.getCallback() [Cannot read property 'set' of undefined]"
I used <ui:inputCheckbox>
Code:
component.find("checkBox")[i].set("v.value", true);
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if (recordfinallist [i].isvalid__C== true)
component.find("checkBox")[i].set("v.value", true);
}
*isvalid__C
is field name
This code is working proper for more than 1 rows but not for one row.
lightning-components javascript visualforce-component helper
add a comment |Â
up vote
1
down vote
favorite
I have used Check all / Uncheck All checkboxes function to select group of Values. I used to display some data in aura iteration with checkbox values checked.
If the data row is more than one its working fine suppose if the row count is one im facing error:
"Uncaught Error in $A.getCallback() [Cannot read property 'set' of undefined]"
I used <ui:inputCheckbox>
Code:
component.find("checkBox")[i].set("v.value", true);
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if (recordfinallist [i].isvalid__C== true)
component.find("checkBox")[i].set("v.value", true);
}
*isvalid__C
is field name
This code is working proper for more than 1 rows but not for one row.
lightning-components javascript visualforce-component helper
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have used Check all / Uncheck All checkboxes function to select group of Values. I used to display some data in aura iteration with checkbox values checked.
If the data row is more than one its working fine suppose if the row count is one im facing error:
"Uncaught Error in $A.getCallback() [Cannot read property 'set' of undefined]"
I used <ui:inputCheckbox>
Code:
component.find("checkBox")[i].set("v.value", true);
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if (recordfinallist [i].isvalid__C== true)
component.find("checkBox")[i].set("v.value", true);
}
*isvalid__C
is field name
This code is working proper for more than 1 rows but not for one row.
lightning-components javascript visualforce-component helper
I have used Check all / Uncheck All checkboxes function to select group of Values. I used to display some data in aura iteration with checkbox values checked.
If the data row is more than one its working fine suppose if the row count is one im facing error:
"Uncaught Error in $A.getCallback() [Cannot read property 'set' of undefined]"
I used <ui:inputCheckbox>
Code:
component.find("checkBox")[i].set("v.value", true);
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if (recordfinallist [i].isvalid__C== true)
component.find("checkBox")[i].set("v.value", true);
}
*isvalid__C
is field name
This code is working proper for more than 1 rows but not for one row.
lightning-components javascript visualforce-component helper
edited Aug 27 at 16:47
battery.cord
6,26951742
6,26951742
asked Aug 27 at 16:01
Issac Pal
13
13
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
component.find()
returns one of three types of value:
- If the local ID is unique, find() returns the component.
- If there are multiple components with the same local ID, find() returns an array of the components.
- If there is no matching local ID, find() returns undefined.
Your code is assuming that the result of find()
is an array, which is why it fails when only a single checkbox is present. You need to be prepared to handle a single return value as well.
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
2
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
add a comment |Â
up vote
4
down vote
component.find()
returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find()
through a custom helper function that ALWAYS returns an array. Like so:
arrayfy: function(component)
//If input is an array, then just return it
//If only one element found, then convert it into a single element array anyway
if(Array.isArray(component))
return component;
else
return component? [component] : ;
,
Use it like so:
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if(recordfinallist[i].isvalid__C == true)
helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
component.find()
returns one of three types of value:
- If the local ID is unique, find() returns the component.
- If there are multiple components with the same local ID, find() returns an array of the components.
- If there is no matching local ID, find() returns undefined.
Your code is assuming that the result of find()
is an array, which is why it fails when only a single checkbox is present. You need to be prepared to handle a single return value as well.
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
2
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
add a comment |Â
up vote
5
down vote
component.find()
returns one of three types of value:
- If the local ID is unique, find() returns the component.
- If there are multiple components with the same local ID, find() returns an array of the components.
- If there is no matching local ID, find() returns undefined.
Your code is assuming that the result of find()
is an array, which is why it fails when only a single checkbox is present. You need to be prepared to handle a single return value as well.
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
2
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
add a comment |Â
up vote
5
down vote
up vote
5
down vote
component.find()
returns one of three types of value:
- If the local ID is unique, find() returns the component.
- If there are multiple components with the same local ID, find() returns an array of the components.
- If there is no matching local ID, find() returns undefined.
Your code is assuming that the result of find()
is an array, which is why it fails when only a single checkbox is present. You need to be prepared to handle a single return value as well.
component.find()
returns one of three types of value:
- If the local ID is unique, find() returns the component.
- If there are multiple components with the same local ID, find() returns an array of the components.
- If there is no matching local ID, find() returns undefined.
Your code is assuming that the result of find()
is an array, which is why it fails when only a single checkbox is present. You need to be prepared to handle a single return value as well.
answered Aug 27 at 16:07
David Reed
19.3k21540
19.3k21540
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
2
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
add a comment |Â
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
2
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
Yes of course im getting "undefined" for this line----> component.find("checkBox")[i]. How to handle it like a single return value as well? Can you please in details with examples.
â Issac Pal
Aug 27 at 16:12
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
how would you check for a single value ? your original question has been answered, if you are unsure how to check for a single value or are facing issues while implementing code for this specific behavior, you might want to open a new post.
â glls
Aug 27 at 16:41
2
2
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
I'd suggest you accept Kal's answer, which provides a good model to follow.
â David Reed
Aug 27 at 17:07
add a comment |Â
up vote
4
down vote
component.find()
returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find()
through a custom helper function that ALWAYS returns an array. Like so:
arrayfy: function(component)
//If input is an array, then just return it
//If only one element found, then convert it into a single element array anyway
if(Array.isArray(component))
return component;
else
return component? [component] : ;
,
Use it like so:
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if(recordfinallist[i].isvalid__C == true)
helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
add a comment |Â
up vote
4
down vote
component.find()
returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find()
through a custom helper function that ALWAYS returns an array. Like so:
arrayfy: function(component)
//If input is an array, then just return it
//If only one element found, then convert it into a single element array anyway
if(Array.isArray(component))
return component;
else
return component? [component] : ;
,
Use it like so:
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if(recordfinallist[i].isvalid__C == true)
helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
add a comment |Â
up vote
4
down vote
up vote
4
down vote
component.find()
returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find()
through a custom helper function that ALWAYS returns an array. Like so:
arrayfy: function(component)
//If input is an array, then just return it
//If only one element found, then convert it into a single element array anyway
if(Array.isArray(component))
return component;
else
return component? [component] : ;
,
Use it like so:
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if(recordfinallist[i].isvalid__C == true)
helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
component.find()
returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find()
through a custom helper function that ALWAYS returns an array. Like so:
arrayfy: function(component)
//If input is an array, then just return it
//If only one element found, then convert it into a single element array anyway
if(Array.isArray(component))
return component;
else
return component? [component] : ;
,
Use it like so:
var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++)
if(recordfinallist[i].isvalid__C == true)
helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
edited Aug 27 at 16:29
answered Aug 27 at 16:05
Kal
1,5641032
1,5641032
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f230244%2fshow-checkbox-while-loading-component%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password