Forum OpenACS Development: Templating: New widgets

Collapse
Posted by Malte Sussdorff on
I'm implementing a new widget (or a widget option, depends on the answers to this thread ...).

Goal: I want to create a "radio_other" widget.This widget is the usual radio one, but has an additional option "other" with a textfield attached. If the user chooses the "other" option, the value in the textfield will be stored.

There are a couple of possible ways to go about it

a) create a new widget
b) add a flag "allow_other" to template::element::create
b) add a flag "widget_options" to template::element::create, that would pass optional widget values to the specific widget (like allow_other or nospell)

Option a) is easier to implement, but introduces tons of widgets.

Option b) is the way that was used for spellchecker support. I don't like it that much because it forces template::element::create to know about attributes that are only specific for one widget.

Option c) sounds like the cleanest solution to me, but also the most work.

Either way, what do you think which way should be pursued? Furthermore, does this require a TIP ?

Collapse
Posted by Dave Bauer on
Malte,

Create a new widget. It can just call the radio widget proc, then call the text widget proc.

Yes, I think what should happen s that any additional properties for a widget should be available to the widget procedure. No need to have an additional option, the element procedure should just pass on anything it can't understand.

Collapse
Posted by russ m on
I've been thinking of implementing this for the menu/select widgets as well, to allow for a selection or "other" choice... whatever way this ends up going it'd be nice if it could also apply to the all the multi-select widget types rather than just radio buttons...
Collapse
Posted by Bruno Mattarollo on

Hey Malte,

Made any progress on this? I am dealing with the same requirement here and I am starting to look at how to create a new widget that would do this.

Tried with creating a widget that would call [input radio ... ] and then append [input text ...] but since I have several options it creates a formgroup and adds the text input box next to every single option of the radio buttons, something like:

( ) [      ] option_label
( ) [      ] option2_label

Any suggestions?

Collapse
Posted by Bruno Mattarollo on
Just a small clarification, it's not really the "label" but the "name" of the option that shows up next to the input text ... :)
Collapse
Posted by Malte Sussdorff on
The way I was pursuing (but got distracted) is to change the /forms/standard.adp for radio. I added this check at the button to insert the textfield. This assumes the widget is called "radio_other". The widget itself would just call "input radio ....".

<if @elements.widget@ in other>
  <input type=text name=\mailto:"@elements.id@.other\">
</if>

Sadly, I did not get the chance to test this thoroughly (previously I was using a hack, where I hardcoded the "other" element as the last one of the options and did a check whether the label was named "other").

If you continue down that road, great, I'll be back on track on monday.