BluePoint
unread,Oct 8, 2008, 1:45:42 PM10/8/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ToscaWidgets-discuss
Paul,
I have been trying out adding CascadingComponentMixin to
various controls from tw,forms and I think it has great potential.
One thing that would be nice would be an extra parameter,
called something like 'event' that allowed one to choose an event
other than 'onchange', for instance, 'onblur' which seems to work
better for a text field. It doesn't look difficult and I had a go at
it but it didnt work, so I obviously don't understand quite what's
going on in the couple of lines of relevant code. If it's clear to you
how to do it, I would be grateful for some guidance so I can modify my
own version.
I found that things like CheckBoxList or RadioList or the
equivalent table versions and Multiple Select did not give me back
quite the output I wanted, so I have worked on a modified version of
dynforms.js This has a somwhat modified version of
tw_cascading_onchange which calls some additional functions which I've
provided but the rest of your code is unmodified aand widgets.py is
unchanged.
Briefly, the extra facilities are:
extra and extra2 can be either a single field name or a list of
field names, so there is no limit on how many fields can be specified.
Fields which can potentially provide multiple values, e.g. a
CheckBoxTable, or a MultipleSelectField will send to the url a string
representation of a list of string values, representing the selected
options, e.g. "['option1','option3']" which can be turned into a
proper Python list by eval. Such fields also send back another value
called 'state' which is a single string in which there is a character
for each option value, checked/selected ones being respresented by 'T'
and unchecked/unselected ones by 'F'. I did this specifically because
it's the way I store this type of info in my database but others might
also find it useful. If the field is the one triggering the AJAX
event, the data comes back as {value:"[.....]", state:'TFTF'} or if
it's a field from extra or extra 2 then it would be
{fieldname:"[........}", fieldname.state:'TFTF'} I'm not sure whether
the dot between fieldname and state is a good idea or whether an
underscore would be better.
Fields which can only provide single values send back a value
string as normal but, if they are fields with options, such a
RadioList or SingleSelectField, there is also a state value defined in
the same way as for multi-valued fields but with at most one 'T'
character the rest being 'F's.
I started on this originally, partly because I wanted changes
in one field to trigger recalculation of one or more others, but also
because, when I submitted a form with a CheckBoxTable, I only ever got
back the name of the first checked option , the rest being ignored.
This problem is solved by the Cascading Mixin version because if I
know which options were checked when the form was first displayed and
AJAX tells me of every change that occurs up to the point the form is
submitted, I don't need to bother with what submit sends back.
If you think any of this could usefully be incorporated in a future
release of tw.dynforms, I could raise a tcket with my version of
dynforms.js attached.