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

DOM-to-Script Object Translator (e.g. jQuery Plugin)

2 Answers 61 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 20 Oct 2009, 01:42 PM
Hello,

Is anyone aware of a (pre-existing) way to get rad controls' script objects from a collection of DOM objects (all of this on the client-side)?

I'll explain (this is a simplistic example, and other solutions apply for this example, but it will illustrate the scenario):
Imagine I want to get a collection of objects on the page, like all rad textboxes that had "Company" in their ID, and I want to clear them.

Outside of rad, I'd use jQuery, something like:
$(":text[id*=Company]").val("");


But say I'd like to use the .clear() function on the script object (the javascript object that is returned by $find(), instead of $get()) -- is there a way to get an array of the script objects if I have a jQuery collection of the DOM objects?

I know that this isn't a strong usage scenario (the .clear() on the script object may be the same as the setting the HTML object's value to empty string), but other scenarios could exist, like setting up events in bulk, changing the selected item on a RadComboBox in bulk, dynamically modifying an object such that you need to use .trackChange() and .commit(), etc.

I also know converting a bunch of DOM objects to a bunch of script objects isn't difficult -- it would essentially be looping over each DOM object in a collection, either examining a property on the DOM object as a filter (to see if represents a Telerik control) before calling $find on the DOM object's ID, or calling $find on all DOM object IDs and checking a property on the script object (if it isn't null; to see if it represented a Telerik control).

I'm asking if some functionality (like a jQuery plugin) had been developed, or is maintained by Telerik, so that you guys can optimize it (maybe there is a way to get the script objects without a loop), or any member of the community, so the effort isn't duplicated.

Anyone aware of a pre-existing methodology or library call to achieve this functionality?

Thanks,

Matthew





2 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 23 Oct 2009, 04:12 PM
Hi,

In fact this can be done relatively easy with "pure" jQuery using the "control" expando:

$("div[class*=RadMenu]").map(function() { return this.control; })

This will return you an array with the client-side objects of all RadMenu instances on the page.

Greetings,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Matthew
Top achievements
Rank 1
answered on 23 Oct 2009, 05:17 PM
Thanks, I believe that was what I was looking for.
Tags
General Discussions
Asked by
Matthew
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or