Reputation: 4690
Say I've got some NewView for a record Order
which is table order
in the database with columns qt
and item
, but when users submit to create a order
row I'd like to also send along some extra data to CreateOrderAction
which will be stored elsewhere or thrown away or logged or whatever. Can I still use formFor
to get the auto-generated form with validation and type-checked fields?
Possible use-cases I've come across so far: honeypot for comment fields, extra row to be created in other tables, count of duplicate entries to add.
If I just
renderForm :: Order -> Html
renderForm order = formFor order [hsx|
{(textField #source) { fieldLabel = "where did you hear about us?" }}
{(numberField #qt)}
{(textField #item)}
|]
where source
is not in Order
, I get Could not deduce (InputValue value0)
.
Upvotes: 0
Views: 117
Reputation: 4690
This was so simple it seems I had found the solution already in my previous IHP project, hopefully a self-answer will save me time in the future :)
Just don't use the textField
(or other *field
helpers), but write out the field html explicitly, and you can still use formFor
for the other fields:
renderForm :: Order -> Html
renderForm Order = formFor order [hsx|
<div class="form-group" id="form-group-order_source">
<label for="order_source">where did you hear about us?</label>
<input type="text" name="source" id="order_source" class="form-control" />
</div>
{(numberField #qt)}
{(textField #item)}
|]
Upvotes: 1