RadListBox help

1 Answer 166 Views
ListBox
rhin
Top achievements
Rank 1
Iron
rhin asked on 28 May 2021, 06:41 AM | edited on 28 May 2021, 10:09 AM

I have RadLisBox custom scripts and am putting focus on ClientLoad()

Something like

Function OnClientLoad(sender, eventsArgs)

{

var RadListBox = $find('radlistbox.clientid')

RadListBox.on('focus', function (e) {
                var index = $('#' + e.target.closest("li").id).index();
                var item = radListControl.get_items().getItem(index);
                if (item) {
                    radListControl.clearSelection();
                    radListControl._activateItem(item, true);
                    item.set_selected(true);
                }
            });

}

item.set_selected(true) give me an error on _updatevalidationfield()

Can I override this code somehow?

 

Edit: There is custom validator attached to this. Think the error is coming from it

EDIT2: I think I figured it out (maybe?). The items within the control are disappearing after some time - probably postback event from validator. I had sort of singleton in place cause I did not need to update the instance of the control. After removing it at least at this point it seems ok. 

 

Attila Antal
Telerik team
commented on 01 Jun 2021, 10:14 AM

What would you like to achieve with the focus? The code is incorrect and is erroring out.

rhin
Top achievements
Rank 1
Iron
commented on 01 Jun 2021, 10:22 AM | edited

it is a pseudo code just giving idea what I am going for (posting 2000 lines code is not a good idea). But yes, I had singleton for selecting the instance of the control however based on research and trials my edit 2 turns out to be correct - on postback the items in the control are returning null. That was fixed by removing the singleton.

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 01 Jun 2021, 11:10 AM

Hello Rhin,

So basically there are 3 things you will need to take into account. The Telerik JavaScript object, the HTML element, and the jQuery object.

function OnClientLoad(sender, eventsArgs) {
    var RadListBox = $find('<%= RadListBox1.ClientID %>'); // This is a Telerik RadListBox object

    var RadListBoxElement = RadListBox.get_element(); // This is the HTML element of the Control

    var $RadListBoxJquery = $(RadListBoxElement); // This is a jQuery object

    // jQuery way of listening to the focus event

    $RadListBoxJquery.on('focus', function (e) {

        // Your logic here

    });
}

 

Telerik & ASP.NET AJAX way of getting client-side reference: Get Client-side Reference to a Control Object

Almost all Telerik objects can return the HTML by calling the .get_element() method. You can use this to pass to the jQuery method.

jQuery requires you to pass an HTML element to its methods: jQuery


Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ListBox
Asked by
rhin
Top achievements
Rank 1
Iron
Answers by
Attila Antal
Telerik team
Share this question
or