digestive-functors icon indicating copy to clipboard operation
digestive-functors copied to clipboard

Inconsistent behavior with subforms (Snap/Heist)

Open cimmanon opened this issue 10 years ago • 0 comments

I have two forms that look similar to this (second form needs to be usable on its own as well as be a part of the first form):

fooForm :: Monad m => Form Text m (Text, Text)
fooForm = ( , )
    <$> "a" .: text Nothing
    <*> "b" .: barForm

barForm :: Monad m => Form Text m Text
barForm = "b" .: choice [("a", "Apple"), ("b", "Banana"), ("c", "Cantaloupe")] (Just "b")

The markup for the first form looks like this:

<dfForm>
    <dfInputText ref="a" />
    <dfInputSelect ref="b" />
    <input type="submit" />
</dfForm>

This generates markup that looks like this:

<form method='POST' enctype='application/x-www-form-urlencoded'>
    <input type='text' id='form.a' name='form.a' value />
    <select id='form.b' name='form.b'><option selected='selected' value='form.b.0'>Apple</option><option value='form.b.1'>Banana</option><option value='form.b.2'>Cantaloupe</option></select>
    <input type='submit' />
</form>

No matter what option you select for the "b" field, you get the 2nd option (the default). For whatever reason, Digestive Functors is able to correctly generate the input element, but it is unable to retrieve the element from the POST. The error, of course, is mine. The form should have looked like this:

fooForm :: Monad m => Form Text m (Text, Text)
fooForm = ( , )
    <$> "a" .: text Nothing
    <*> barForm

Digestive Functors, however, should have generated a run time error. There is no "b" field in the outer form: it is a subform that contains a "b" field.

cimmanon avatar Jan 28 '14 16:01 cimmanon