Hi,

When develooing widgets, what's the best recommended method to access
them from javascript?

Let me explain with an example:

Assuming I have a widget displaying a google map, and I want to
display that more than once on a page, but each with different
locations and/or settings. I would need to set these parameters using
javascript obviously. But for simple widgets I don't have the
"form_id" variable available, so I have no *uniqe* way of identifying
them on the page (say a HTML-ID attribute). Or is there and I am
missing it?

In my current application, I have a list of items, each having a
unique ID in the database. So I now simply loop through them in the
template, give the containing HTML-Tag an ID with the database ID and
right after the container I create a <script> tag in which I make the
appropriate JS calls.

This looks hackish to me, and I'd rather have the JS code inside a
"JSSource" instance inside the widget code. I understand that the
widget cannot know anything about this at the time it is instantiated
as it is stateless. This information could only be available when
"widget.display" is called. Is this correct?

This whole concept makes me still a bit dizzy as I have not /yet/ the
whole "big picture" in my mind how all in TurboGears is tied together.

What I really would like to know: Is the way I am approaching it (with
the <script> tag in the template) the best/recommended way to do it?
Or are there other best practices for this case.

This still leaves me the situation that non-form widgets have no
"field_id" which makes identifying difficult if you have more of them
on a page. If you have a database ID (or something similar) at hand as
in my first example, this is trivial. Otherwise you would need you
somehow supply a manual HTML-ID to the widget at display time, which I
guess should be possible.

To be honest I beleive I already answered myself while writing this
post. As usual, once you start explaining a problem, the solution
comes by itself. Still, I would like to hear your input/thoughts on
this issue. This is something that bugs me already for quite some
time. Who knows, maybe I am missing something dead-simple (as I
already did last time with template-file for widgets) again.

So the way I see it, there are two cases:
 1) form-widgets
 2) simple widgets

Suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to