[html-formfu] combo box equivalent
Malcolm
mjh-formfu at liminalflux.net
Sun Aug 31 16:48:42 BST 2008
On Tuesday 26 August 2008, Carl Franks wrote:
> >> > Is there a good way of doing a combo-box type element for a form? I've
> >> > tried several variations, but so far I haven't found anything that
> >> > doesn't end up requiring custom coding on the handler.
> >> >
> >> > This is the closest I've gotten, but their doesn't seem to be a way of
> >> > enforcing the SingleValue constraint.
> >> Because Multi is also a Field-element, when you add a constraint to
> >> it, it doesn't get added to its children, unlike with other Block
> >> elements.
> >> If you add the constraint to one of the "country" fields, it should
> >> work.
> > The reason I tried it on the Multi element is that it didn't work on the
> > member fields, as there's two child elements with the same name,
> > SingleValue fails.
> I've added a test for what I think you're describing, and it seems to work
> okay. Can you have a look, and let me know if I'm not getting it?
>
http://code.google.com/p/html-formfu/source/browse/trunk/HTML-FormFu/t/elements/combo_box.t
>
http://code.google.com/p/html-formfu/source/browse/trunk/HTML-FormFu/t/elements/combo_box.yml
If I plug in the contents of combo_box.yml into my form it doesn't work,
so one of us is missing something.
There are two issues with the combo_box.yml:
* If the form is filled with default values (which I do, using
$form->model->default_values(...)), then both fields are filled out,
resulting in a definite double, if identical, value if submitted unaltered.
* Even with no text in the text box, the SingleValue constraint is still
failing.
What I think is wrong with the test is that it's not actually doing a round
trip through the generated html, which looks like this:
<form action="" method="post">
<fieldset>
<div class="multi">
<span class="elements">
<select name="foo">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
<input name="foo" type="text" />
</span>
</div>
<div class="submit">
<input name="submit" type="submit" />
</div>
</fieldset>
</form>
When you submit that form, the text field has an empty value, not a
non-existant one.
There's also a missing test case of the "nothing selected from dropdown, but
text in field" variant, as there's no available empty value from the
dropdown.
More information about the HTML-FormFu
mailing list