Re: [racket-users] Formlets: No binding for 'select-input' without selection and values bound to binding:form

2017-12-22 Thread Christian
Hi Jay,

* Thanks a ton for your fast, detailed and working response!

* Quite a few points of how to use formlets became clear because of your answer.
  - E.g., I changed the text input to a simple ,{input-string . => .
name-filter}

* Perhaps something like your checkbox example could be added to the
formlet documentation, because honestly I could not have deduced the
usage from the single function descriptions...

Cheers,
Christian

On 21 December 2017 at 18:56, Jay McCarthy  wrote:
> Hi,
>
> I would write this code like this
>
> ```
> #lang web-server/insta
> (require web-server/http/bindings
>  web-server/formlets
>  web-server/formlets/lib
>  web-server/formlets/input)
>
> (struct stop (id name))
>
> (define stops
>   (list (stop 1 "Foo")
> (stop 2 "Bar")
> (stop 3 "Baz")))
>
> (define (start request)
>   (render-info-page request))
>
> (define form-formlet
>   (formlet
>(#%# (div ,{(multiselect-input
> stops
> #:multiple? #f
> #:attributes '((size "40"))
> #:display (lambda (stop) (stop-name stop)))
>. => . stop})
> (div ,{(cross (pure (λ (x) (and x #t)))
>   (checkbox "" #t))
>. => . use-name-filter?}
>  "Name filter "
>  ,{(to-string (default #"" (text-input))) . => . name-filter}))
>(values stop use-name-filter? name-filter)))
>
> (define (render-info-page request)
>   (printf "request bindings: ~v~n"
>   (force (request-bindings/raw-promise request)))
>   (define-values (stops use-name-filter? name-filter)
> (formlet-process form-formlet request))
>   (define stop
> (if (pair? stops) (car stops) #f))
>   (printf "stop: ~v, use-name-filter?: ~v, name-filter: ~v~n"
>   stop use-name-filter? name-filter)
>   (define (response-generator embed/url)
> (response/xexpr
>  `(html
>(head (title "Stop Info"))
>(body (h1 "List of Stops")
>  (h2 ,(if stop
> (stop-name stop)
> "no stop selected"))
>  (form ([action ,(embed/url render-info-page)])
>,@(formlet-display form-formlet)
>(p (input ([type "submit"]
>  
>   (send/suspend/dispatch response-generator))
> ```
>
> I will change `select-input` to not error on empty input and instead
> return #f, that seems like what is expected.
>
> Jay
>
>
> On Thu, Dec 21, 2017 at 9:32 AM, Christian <7enderh...@gmail.com> wrote:
>> * I have boiled down my problem to the minimal example at the end of the
>> post
>>
>> * Basically, I'm running a formlet form in 'cycles' on itself to filter some
>> list data
>>
>> * on the initial invocation, the bindings in the request are empty, as
>> expected:
>> request bindings: ()
>> stop: #f, use-name-filter?: #f, name-filter: #f
>>
>> * submitting the form without selecting a list item results in the binding
>> for the list to be missing (hence a contract violation on parsing by
>> formlet-process, which results in default values):
>> request bindings: (#(struct:binding:form input_1 ) #(struct:binding:form
>> input_2 ))
>> stop: #f, use-name-filter?: #f, name-filter: #f
>>
>> * even when selecting a list item, the other values are not bound to their
>> 'control values' (boolean and string), but to the binding:form structs:
>> request bindings: (#(struct:binding:form input_0 0) #(struct:binding:form
>> input_1 ) #(struct:binding:form input_2 abc))
>> stop: #, use-name-filter?: #(struct:binding:form input_1 ),
>> name-filter: #(struct:binding:form input_2 abc)
>>
>> * (the problem is the same with a different handler for the submit button,
>> without the form returning to itself)
>>
>> * Any suggestions on what I most probably misunderstand would be welcome.
>>
>> Thanks for your consideration,
>> Christian
>>
>> Example:
>>
>> #lang web-server/insta
>>
>> (require web-server/http/bindings)
>> (require web-server/formlets)
>> (require web-server/formlets/input)
>>
>> (struct stop (id name))
>>
>> (define stops (list (stop 1 "Foo")
>> (stop 2 "Bar")
>> (stop 3 "Baz")))
>>
>> (define (start request)
>>   (render-info-page request))
>>
>> (define form-formlet
>>   (formlet
>>(#%# (div ,{(select-input stops
>>  #:attributes '((size "40"))
>>  #:display (lambda (stop)
>>  (stop-name stop))) . => . stop})
>> (div ,{(checkbox "" #t) . => . use-name-filter?}
>>  "Name filter "
>>  ,{(text-input) . => . name-filter}))
>>(values stop use-name-filter? name-filter)))
>>
>> (define (render-info-page request)
>>   (printf "request bindings: ~a~n" (force (request-bindings/raw-promise
>> request)))
>>   (define-values (stop use-name-filter? name-filter)
>> (with-handlers ([(lambda (e) #t) (lambda (e) (values #f #

Re: [racket-users] Formlets: No binding for 'select-input' without selection and values bound to binding:form

2017-12-21 Thread Jay McCarthy
Hi,

I would write this code like this

```
#lang web-server/insta
(require web-server/http/bindings
 web-server/formlets
 web-server/formlets/lib
 web-server/formlets/input)

(struct stop (id name))

(define stops
  (list (stop 1 "Foo")
(stop 2 "Bar")
(stop 3 "Baz")))

(define (start request)
  (render-info-page request))

(define form-formlet
  (formlet
   (#%# (div ,{(multiselect-input
stops
#:multiple? #f
#:attributes '((size "40"))
#:display (lambda (stop) (stop-name stop)))
   . => . stop})
(div ,{(cross (pure (λ (x) (and x #t)))
  (checkbox "" #t))
   . => . use-name-filter?}
 "Name filter "
 ,{(to-string (default #"" (text-input))) . => . name-filter}))
   (values stop use-name-filter? name-filter)))

(define (render-info-page request)
  (printf "request bindings: ~v~n"
  (force (request-bindings/raw-promise request)))
  (define-values (stops use-name-filter? name-filter)
(formlet-process form-formlet request))
  (define stop
(if (pair? stops) (car stops) #f))
  (printf "stop: ~v, use-name-filter?: ~v, name-filter: ~v~n"
  stop use-name-filter? name-filter)
  (define (response-generator embed/url)
(response/xexpr
 `(html
   (head (title "Stop Info"))
   (body (h1 "List of Stops")
 (h2 ,(if stop
(stop-name stop)
"no stop selected"))
 (form ([action ,(embed/url render-info-page)])
   ,@(formlet-display form-formlet)
   (p (input ([type "submit"]
 
  (send/suspend/dispatch response-generator))
```

I will change `select-input` to not error on empty input and instead
return #f, that seems like what is expected.

Jay


On Thu, Dec 21, 2017 at 9:32 AM, Christian <7enderh...@gmail.com> wrote:
> * I have boiled down my problem to the minimal example at the end of the
> post
>
> * Basically, I'm running a formlet form in 'cycles' on itself to filter some
> list data
>
> * on the initial invocation, the bindings in the request are empty, as
> expected:
> request bindings: ()
> stop: #f, use-name-filter?: #f, name-filter: #f
>
> * submitting the form without selecting a list item results in the binding
> for the list to be missing (hence a contract violation on parsing by
> formlet-process, which results in default values):
> request bindings: (#(struct:binding:form input_1 ) #(struct:binding:form
> input_2 ))
> stop: #f, use-name-filter?: #f, name-filter: #f
>
> * even when selecting a list item, the other values are not bound to their
> 'control values' (boolean and string), but to the binding:form structs:
> request bindings: (#(struct:binding:form input_0 0) #(struct:binding:form
> input_1 ) #(struct:binding:form input_2 abc))
> stop: #, use-name-filter?: #(struct:binding:form input_1 ),
> name-filter: #(struct:binding:form input_2 abc)
>
> * (the problem is the same with a different handler for the submit button,
> without the form returning to itself)
>
> * Any suggestions on what I most probably misunderstand would be welcome.
>
> Thanks for your consideration,
> Christian
>
> Example:
>
> #lang web-server/insta
>
> (require web-server/http/bindings)
> (require web-server/formlets)
> (require web-server/formlets/input)
>
> (struct stop (id name))
>
> (define stops (list (stop 1 "Foo")
> (stop 2 "Bar")
> (stop 3 "Baz")))
>
> (define (start request)
>   (render-info-page request))
>
> (define form-formlet
>   (formlet
>(#%# (div ,{(select-input stops
>  #:attributes '((size "40"))
>  #:display (lambda (stop)
>  (stop-name stop))) . => . stop})
> (div ,{(checkbox "" #t) . => . use-name-filter?}
>  "Name filter "
>  ,{(text-input) . => . name-filter}))
>(values stop use-name-filter? name-filter)))
>
> (define (render-info-page request)
>   (printf "request bindings: ~a~n" (force (request-bindings/raw-promise
> request)))
>   (define-values (stop use-name-filter? name-filter)
> (with-handlers ([(lambda (e) #t) (lambda (e) (values #f #f #f))])
>   (formlet-process form-formlet request)))
>   (printf "stop: ~a, use-name-filter?: ~a, name-filter: ~a~n" stop
> use-name-filter? name-filter)
>   (define (response-generator embed/url)
> (response/xexpr
>  `(html
>(head (title "Stop Info"))
>(body (h1 "List of Stops")
>  (h2 ,(if stop
>   (stop-name stop)
>   "no stop selected"))
>  (form ([action ,(embed/url render-info-page)])
>,@(formlet-display form-formlet)
>(p (input ([type "submit"]
>  
>   (send/suspend/dispatch response-generator))
>
> --
> You receiv

[racket-users] Formlets: No binding for 'select-input' without selection and values bound to binding:form

2017-12-21 Thread Christian
* I have boiled down my problem to the minimal example at the end of the 
post

* Basically, I'm running a formlet form in 'cycles' on itself to filter 
some list data

* on the initial invocation, the bindings in the request are empty, as 
expected:
request bindings: ()
stop: #f, use-name-filter?: #f, name-filter: #f

* submitting the form without selecting a list item results in the binding 
for the list to be missing (hence a contract violation on parsing by 
formlet-process, which results in default values):
request bindings: (#(struct:binding:form input_1 ) #(struct:binding:form 
input_2 ))
stop: #f, use-name-filter?: #f, name-filter: #f

* even when selecting a list item, the other values are not bound to their 
'control values' (boolean and string), but to the binding:form structs:
request bindings: (#(struct:binding:form input_0 0) #(struct:binding:form 
input_1 ) #(struct:binding:form input_2 abc))
stop: #, use-name-filter?: #(struct:binding:form input_1 ), 
name-filter: #(struct:binding:form input_2 abc)

* (the problem is the same with a different handler for the submit button, 
without the form returning to itself)

* Any suggestions on what I most probably misunderstand would be welcome.

Thanks for your consideration,
Christian

Example:

#lang web-server/insta

(require web-server/http/bindings)
(require web-server/formlets)
(require web-server/formlets/input)

(struct stop (id name))

(define stops (list (stop 1 "Foo")
(stop 2 "Bar")
(stop 3 "Baz")))

(define (start request)
  (render-info-page request))

(define form-formlet
  (formlet
   (#%# (div ,{(select-input stops
 #:attributes '((size "40"))
 #:display (lambda (stop)
 (stop-name stop))) . => . stop})
(div ,{(checkbox "" #t) . => . use-name-filter?}
 "Name filter "
 ,{(text-input) . => . name-filter}))
   (values stop use-name-filter? name-filter)))

(define (render-info-page request)
  (printf "request bindings: ~a~n" (force (request-bindings/raw-promise 
request)))
  (define-values (stop use-name-filter? name-filter)
(with-handlers ([(lambda (e) #t) (lambda (e) (values #f #f #f))])
  (formlet-process form-formlet request)))
  (printf "stop: ~a, use-name-filter?: ~a, name-filter: ~a~n" stop 
use-name-filter? name-filter)
  (define (response-generator embed/url)
(response/xexpr
 `(html
   (head (title "Stop Info"))
   (body (h1 "List of Stops")
 (h2 ,(if stop
  (stop-name stop)
  "no stop selected"))
 (form ([action ,(embed/url render-info-page)])
   ,@(formlet-display form-formlet)
   (p (input ([type "submit"]
 
  (send/suspend/dispatch response-generator))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.