[racket] formlet-fill

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Nov 18 18:10:29 EST 2011

You need to make a new formlet that knows about the default values.

We could imagine a macro that makes this nicer, but in general it will need
to be something that creates a new one.

Is there some reason you don't want to do that?

I can imagine something like (formlet-display) that took the old values,
but then it would be more monad-like than arrow-like, and wouldn't really
be a formlet. If you can clarify your use case, it may be worth
investigating.

Jay

On Fri, Nov 18, 2011 at 1:13 PM, Jordan Schatz <jordan at noionlabs.com> wrote:

>
> I have a pattern of user interaction that is common in my web app:
>
> I have a db record, I present it to the user in a form, the user edits
> the form, submits it, server side logic validates it, and then returns
> the same form with the updated record.
>
> I want to port the app to Racket, and I thought formlets would be just
> the thing, but I don't see how to fill the values into the formlet
> without making a new formlet... seems I need a (formlet-fill
> (some-values)) to go along with the formlet-display and formlet-process.
>
> Here is what I have: (Which doesn't work)
>
> ----------------------------------------------------------------------
> #lang web-server/insta
>
> (require web-server/formlets)
>
> (define record (hasheq 'title "this is a title"
>                       'body "post body"))
>
> (define (start request)
>  (edit-record request))
>
> (define (edit-record request)
>  (local [(define (record-formlet our-values)
>            (formlet
>             (#%# ,{(text-input #:value (string->bytes/utf-8 (hash-ref
> our-values 'title))) . => . title}
>                  ,{(text-input #:value (string->bytes/utf-8 (hash-ref
> our-values 'body))) . => . body})
>             (values title body)))
>
>          (define (handle-response request)
>            (define-values (title body)
>              (formlet-process our-formlet request))
>            (set! record (hasheq 'title title
>                                 'body body))
>            (start (redirect/get)))
>
>          (define (response-generator embed/url)
>            (response/xexpr
>             `(html
>               (form ([action ,(embed/url handle-response)])
>                     ,@(formlet-display our-formlet)
>                     (input ([type "submit"]))))))]
>
>          (send/suspend/dispatch response-generator)))
>
> ----------------------------------------------------------------------
>
> It seems like this would be a very common pattern... what is the "normal"
> way to do it?
>
> Thanks,
> Jordan
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111118/27563baf/attachment.html>

Posted on the users mailing list.