Alberto Valverde <[EMAIL PROTECTED]> writes:

> FormFieldsContainers (Forms and FieldSets) now [1855] provide a  
> function called "field_for" to their template for easier and more  
> powerful template layout. Without it it was impossible to grab a  
> subfield's effective 'field_id' or 'name' (for javascripting) or it's  
> label (for <label />).

This is very helpful indeed but it doesn't help with reusability of individual
widgets...  I was thinking more along the lines of something that allowed me
doing this:


class WidgetsSelectCountry(widgets.WidgetsList):
    country = widgets.SingleSelectField(
        label = _(u'Country'),
        options = model.make_list(
            model.Country, None, 'shortName',
            orderBy = model.Pais.q.shortName),
        default = brasil.id,
        validator = validators.Int(not_empty=True),
        javascript = [widgets.JSSource(
            src = """
            <script type="text/javascript">
              connect('${fq_name}',
                'onchange',
                getStatesForCountry);
            </script>
            """, location=widgets.js_location.bodybottom)])


Where "${fq_name}" would be replaced by the full id of the element no matter
where the widget was rendered.  Then, to use it in a form I could do:

my_form = widgets.TableForm(
    name = 'this_is_my_form',
    fields = [WidgetsSelectCõuntry()])


And it would render the above javascript as

   <SCRIPT TYPE="text/javascript">
     connect('this_is_my_form.country', 
       'onchange', 
       getStatesForCountry);
   </SCRIPT>

at the bottom of the page.


Today I can't insert JavaScript and reuse the widget in an easy way...  I have
to do some "nasty" workarounds and pass parameters to inform the resulting
name everytime I instantiate such widget.

If your changes could be applied to this kind of use of JSSource besides Form
derived classes it would be great.


-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to