Dynamic form view

21 views
Skip to first unread message

Warren Lynn

unread,
May 30, 2010, 1:27:55 AM5/30/10
to weblocks
Hi,

I wonder how I can make a dynamic form view. What I need is:

I have two fields, one is radio button selection (a (member ...) type slot), another is a drop down. I wish to have different choices in the drop down list depending on the radio button selection.

Can anyone give some suggestions on that? Thanks a lot.

Warren

Leslie P. Polzer

unread,
May 30, 2010, 5:13:31 AM5/30/10
to webl...@googlegroups.com

Warren Lynn wrote:

You need some Javascript to change the dropdown choices when one of
the radio buttons is clicked.

Does that help?

Perhaps nunb can add his two cents too.

Warren Lynn

unread,
May 30, 2010, 11:30:12 AM5/30/10
to webl...@googlegroups.com
You need some Javascript to change the dropdown choices when one of
the radio buttons is clicked.

Does that help?

Perhaps nunb can add his two cents too.

Thanks. I was just wondering whether there is any built-in form widget option that will allow the input of one field affecting another input field. Looks like I will need to define my own widget to do that.

Nandan Bagchee

unread,
May 30, 2010, 5:22:28 PM5/30/10
to webl...@googlegroups.com
 You need some Javascript to change the dropdown choices when one of
the radio buttons is clicked.

Does that help?

Perhaps nunb can add his two cents too.

Thanks. I was just wondering whether there is any built-in form widget option that will allow the input of one field affecting another input field.


In the interim I've been writing the custom-2c-radio-presentation.. ;-)

The easy way to propagate changes between the radio and the dropdown is to mark the form dirty, and have presentation-choices calculated afresh for the dropdown. The problem is that pretty much all input fields etc. get reset to blanks. A simple onchange applied per-field (Saikat's extant work) would make this route feasible, by storing updated form values in intermediate-values.

 
Looks like I will need to define my own widget to do that.
 

This would be much easier if field presentations were themselves widgets, and there is some momentum towards that..

Depending on how much of the logic you want to keep in lisp (is having it inside parenscript close enough?) and how tightly coupled the radio presentation and the dropdown should be, I guess a presentation to do that could be arranged. Also, it's a common use-case (the other use-case is hiding and showing divs) and so should be baked in..

What about another option, having two dropdowns in your form, and selectively hiding them? Custom writers could be used if you want to update a common slot.

The problem with this is that if you write your logic CL-side, there's going to be a delay (and the ajax-call gif display) before the dropdown values are switched. If it were done totally through javascript, this delay would not exist. Furthermore, UX wise it's good to animate the change, and the current Weblocks update mechanism doesn't allow for animation hooks
 

Warren Lynn

unread,
May 31, 2010, 1:32:33 AM5/31/10
to weblocks

Thanks a lot for such detailed explanation and analysis. I do not
understand everything here, so I will definitely come back to this
post after I dig a little bit deeper. And good to know someone may
have a cool solution soon for that. I am more inclined to keeping the
refresh logic in lisp, as that is more flexible and can handle large
data sets (since the client does not need to download the whole set in
one shot), although I suspect a pure client side javascript solution
should work well for most cases.


Nandan Bagchee

unread,
May 31, 2010, 6:27:47 AM5/31/10
to webl...@googlegroups.com
post after I dig a little bit deeper.

I hope to post some code for this soon. The problem is that it's a bit hackish in that the abstraction/dsl is not clean enough.

I am more inclined to keeping the
refresh logic in lisp, as that is more flexible and can handle large
data sets (since the client does not need to download the whole set in
one shot),

I think the best solution would be something like the suggest-presentation .. the only problem is, we have to tell the radio buttons presentation about the dropdown which needs to be changed, iow, how does one identify the dropdown? (through its presentation-dom-id) ? 
 
although I suspect a pure client side javascript solution
should work well for most cases.

I would highly recommend special-casing a presentation using javascript for this case, see for example this code. It has a half-working custom-2c-radio presentation (haven't figured out how to refresh/redraw the dropdown yet) and the rest of it is a presentation which shows or hides other fields depending on the value of a dropdown. I can't suggest this approach (though it works) because it all depends on using templated form views(which is why I can easily identify the divs that need to be hidden or shown, something that's hard to do with regular form-views; divs also serve as a unit of grouping, grouping is also handled well by the wizard-form)

Weblocks aims to degrade gracefully when javascript is disabled. Applying that precept to your situation, it would seem to me that using the wizard-form would be the best solution.
On page x you select the appropriate radio button / checkbox, and then, on page (+1 x) of the form the dropdown is automatically populated with the right values. Going back and forth also presents no problem[1], and of course it works perfectly when javascript is disabled.

[1] As long as presentation-choices is a function that looks at the radio presentation slot value to decide..

Warren Lynn

unread,
Jun 1, 2010, 1:37:57 PM6/1/10
to webl...@googlegroups.com

Thanks a lot. I will need some time to digest this as the Weblocks internals are still quite fuzzy to me.

Reply all
Reply to author
Forward
0 new messages