This is a migrated thread and some comments may be shown as answers.

findItemByValue not working using concatenated string as parameter

1 Answer 8 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
jlj30
Top achievements
Rank 2
jlj30 asked on 12 Jun 2015, 11:59 PM

Hi,

I'm sure this is something silly on my part, but I can't spot it.

The following code works:

var x = 'text';
var y = 'Red';
var selectedColorButtonValue = String(x + y);
var selectedColorButton = toolBar.findItemByValue(selectedColorButtonValue);

Now, since the actual value of y is dynamic and only known at run time, I have this code:

var selectedColorButtonValue = getColorButtonValue(fontColor); // Returns 'Red' for this demo
selectedColorButtonValue = String('text' + selectedColorButtonValue);
var selectedColorButton = toolBar.findItemByValue(selectedColorButtonValue);

The above does NOT work. The toolbarbutton that I'm trying to find is not found!

The toolbarbutton in question is one of several items in a RadToolBarSplitButton.

I have written to the console, and the value of selectedColorButtonValue appears fine.

Can anyone spot what I'm doing wrong.

Thanks

Jim

 

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 17 Jun 2015, 06:19 AM
Hi,

Make sure that you pass the correct id to $find:

function findItem() {
    var toolBar = $find("<%= toolbar.ClientID %>");
    var x = 'text';
    var y = 'Red';
    var selectedColorButtonValue = String(x + y);
    var selectedColorButton = toolBar.findItemByValue(selectedColorButtonValue);
}
<telerik:RadToolBar runat="server" ID="toolbar">
         <Items>
             <telerik:RadToolBarButton Text="Button" Value="textRed">
                 <ItemTemplate>
                     button
                 </ItemTemplate>
             </telerik:RadToolBarButton>
         </Items>
     </telerik:RadToolBar>


Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ToolBar
Asked by
jlj30
Top achievements
Rank 2
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or