Hi,

I've committed the change at r959 (Alberto, take a look when you can
;-)), all tests are running fine tough and hopefully.

Notice for people doing compound widgets with TG svn, you need to
change something (most probably removing no more needed code), as an
example I post the AutocompleteField diff:

+    widgets = ["text_field", "hidden_field"]
     template_vars = ["search_controller", "search_param",
"result_name", "attrs"]
+    text_field = TextField(name="text")
+    hidden_field = HiddenField(name="hidden")
     attrs = {}
     search_controller = ""
     search_param = "searchString"
     result_name = "textItems"

-    def __init__(self, name=None, text_field=None, hidden_field=None,
**kw):
-        super(AutoCompleteField, self).__init__(name, **kw)
-        self.widgets["text_field"] = text_field or
TextField(name="text")
-        self.widgets["hidden_field"] = hidden_field or
HiddenField(name="hidden")
-
-    def update_data(self, d):
-        super(AutoCompleteField, self).update_data(d)
-        d["text_field"] = self.widgets["text_field"]
-        d["hidden_field"] = self.widgets["hidden_field"]
-

Isn't that nice? ;-)

Ciao
Michele

Michele Cella wrote:
> Hi guys,
>
> The last (small) polish I think we need to flash out for the widget API
> is related to the use of the widgets attribute in CompoundWidgets.
>
> Background: actually every children widget of a CompoundWidget should
> be kept inside self.widgets that's a dictionary, this let's us prepare
> some methods to generate a Schema and retrieve css and javascript
> programmatically.
>
> The problem: some times ago Alberto added the ability to use a widget
> Form in the following way:
>
> MyForm(Form):
>     fields = [list of predefined fields]
>
> that's a good and probably expected use by even other people since you
> pass fields using the fields parameter, what looks strange is that in
> __init__ we then copy (a reference in reality) those fields inside our
> self.widgets in this way:
>
>   self.widgets = fields or self.fields or []
>
> this seems a bit strange to me, the right way of doing this thing
> should be:
>
> MyForm(Form):
>     widgets["fields"] = [list of predefined fields]
>
> but this is a bit more difficult to explain and not coherent with the
> fields parameter you can pass at init.
>
> So here is my proposal, make widgets a list like template_vars for a
> form this will mean something like this:
>
> widgets = ["fields", "submit"]
> fields = []
> submit = SubmitButton()
>
> def __init__(self, fields, submit, ...):
>        if fields:
>            self.fields = fields
>        if submit:
>            self.submit = submit
>
> we could even make that automated (like template_vars) but only for
> init so that we are sure everyone is doing the right thing, not sure
> about this last point tough.
>
> this looks pretty nice, well behaving and probably more explicit (to
> external observer we are declaring where our widgets are), the only
> modification we need is for schema generation and retrieve_css,
> retrieve_javascript that should iterate over self.widgets to collect
> the place to look at.
>
> Opinions? this will require a small fix for other CompoundWidget user
> by the way.
> Kevin, what do you think?
>
> Personally I think this is really the last eventual polish needed.
> 
> Ciao
> Michele


--~--~---------~--~----~------------~-------~--~----~
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