[web-devel] Yesod: generating code for optional vs required fields.

Michael Snoyman michael at snoyman.com
Fri Oct 15 12:48:46 CEST 2010


Sorry, accidently replied off-list last time. Anyway, code looks good,
and I've pulled it into the ver0.6 branch.

Thanks!

Michael

On Fri, Oct 15, 2010 at 1:56 AM, Matt Brown <matt at softmechanics.net> wrote:
> Adding fiRequired worked for me, and was quite painless:
> http://github.com/softmechanics/yesod/commit/77eb435a629717f063f7a31190162344b0fc6a7f
>
> Now my fieldToDivs is:
>
> fieldsToDivs :: FormField sub y a -> Form sub y a
> fieldsToDivs = mapFormXml $ mapM_ go
>  where
>    go fi = do
>        let cls = string $ if fiRequired fi then "fm-req" else "fm-opt"
>        wrapWidget (fiInput fi) $ \w -> [$hamlet|
> %div!class=$cls$
>  %label!for=$fiIdent.fi$ $fiLabel.fi$
>    .tooltip $fiTooltip.fi$
>  ^w^
>  $maybe fiErrors.fi err
>   %div.errors $err$
> |]
>
> -matt
>
> On Thu, Oct 14, 2010 at 1:46 PM, Matt Brown <matt at softmechanics.net> wrote:
>> Hello all,
>>
>> I'm new to Yesod, and I'm trying to render my forms like this:
>> http://www.stylephreak.com/uploads/source/cssforms/cssform.php.
>>
>> This has two main requirements: Use divs instead of tables, and
>> specify whether the field is required or optional.  This is what I
>> have so far:
>>
>> fieldsToDivs :: FormField sub y a -> Form sub y a
>> fieldsToDivs = mapFormXml $ mapM_ go
>>  where
>>    go fi = do
>>        let cls = string $ if fieldRequired fi then "fm-req" else "fm-opt"
>>        wrapWidget (fiInput fi) $ \w -> [$hamlet|
>> %div!class=$cls$
>>  %label!for=$fiIdent.fi$ $fiLabel.fi$
>>    .tooltip $fiTooltip.fi$
>>  ^w^
>>  $maybe fiErrors.fi err
>>   %div.errors $err$
>> |]
>>
>> fieldRequired _ = True
>>
>> I'm not sure how to implement fieldRequired.  Is there a way to infer
>> required/optional from FieldInfo?  Would it make sense to add
>> fiRequired :: Bool to FieldInfo?
>>
>> thanks,
>> -matt
>>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>


More information about the web-devel mailing list