diff options
author | Danjela Lura <danielaluraa@gmail.com> | 2020-05-29 17:27:13 +0200 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-06-07 20:17:03 +0100 |
commit | 14cd95f2449a8917850be7c0e9e0bb0cc5420a7f (patch) | |
tree | 77d0358c8b199339cc896b56a7d0ac6b87d8d0eb /guix-data-service | |
parent | ecd460867bf905f6c5b18a7ef152cb057d446a7b (diff) | |
download | data-service-14cd95f2449a8917850be7c0e9e0bb0cc5420a7f.tar data-service-14cd95f2449a8917850be7c0e9e0bb0cc5420a7f.tar.gz |
Make the form-horizontal-control procedure aware of hidden inputs
Signed-off-by: Christopher Baines <mail@cbaines.net>
Diffstat (limited to 'guix-data-service')
-rw-r--r-- | guix-data-service/web/view/html.scm | 240 |
1 files changed, 125 insertions, 115 deletions
diff --git a/guix-data-service/web/view/html.scm b/guix-data-service/web/view/html.scm index 39f2101..d734cd0 100644 --- a/guix-data-service/web/view/html.scm +++ b/guix-data-service/web/view/html.scm @@ -133,123 +133,133 @@ (invalid-query-parameter? val)))) (show-help-span? (or help-text has-error? required?))) - `(div - (@ (class ,(string-append - "form-group form-group-lg" - (if has-error? " has-error" "")))) - (label (@ (for ,input-id) - (class "col-sm-2 control-label")) - ,label) - (div - (@ (class "col-sm-9")) - ,(if options - `(select (@ (class "form-control") - (style ,(if font-family - (string-append - "font-family: " font-family ";") - "")) - ,@(if allow-selecting-multiple-options - '((multiple #t)) - '()) - (id ,input-id) - ,@(if show-help-span? - `((aria-describedby ,help-span-id)) - '()) + (if (string=? type "hidden") + `(input (@ (class "form-control") + (id ,input-id) + (type ,type) + (name ,input-name) + ,@(match (assq (string->symbol input-name) + query-parameters) + (#f '()) + ((_key . value) + `((value ,(value->text value))))))) + `(div + (@ (class ,(string-append + "form-group form-group-lg" + (if has-error? " has-error" "")))) + (label (@ (for ,input-id) + (class "col-sm-2 control-label")) + ,label) + (div + (@ (class "col-sm-9")) + ,(if options + `(select (@ (class "form-control") + (style ,(if font-family + (string-append + "font-family: " font-family ";") + "")) + ,@(if allow-selecting-multiple-options + '((multiple #t)) + '()) + (id ,input-id) + ,@(if show-help-span? + `((aria-describedby ,help-span-id)) + '()) - (name ,input-name)) - ,@(let ((selected-options - (match (assq (string->symbol input-name) - query-parameters) - ((_key . value) - (if (not allow-selecting-multiple-options) - (list value) - value)) - (_ '())))) + (name ,input-name)) + ,@(let ((selected-options + (match (assq (string->symbol input-name) + query-parameters) + ((_key . value) + (if (not allow-selecting-multiple-options) + (list value) + value)) + (_ '())))) - (map (match-lambda - ((option-label . option-value) - `(option - (@ ,@(if (member (if (and - (string? option-value) - (string=? option-value - null-string-value)) - "" - option-value) - selected-options) - '((selected "")) - '()) - (value ,option-value)) - ,(value->text option-label))) - (option-value - `(option - (@ ,@(if (member (if (and - (string? option-value) - (string=? option-value - null-string-value)) - "" - option-value) - selected-options) - '((selected "")) - '())) - ,(value->text option-value)))) - options))) - `(input (@ (class "form-control") - (style ,(if font-family - (string-append - "font-family: " font-family ";") - "")) - (id ,input-id) - (type ,type) - ,@(if required? - '((required #t)) - '()) - ,@(if show-help-span? - `((aria-describedby ,help-span-id)) - '()) - (name ,input-name) - ,@(match (assq (string->symbol input-name) - query-parameters) - (#f '()) - ((_key . ($ <invalid-query-parameter> value)) - (if (string=? type "checkbox") - (if value - '((checked #t)) - '()) - `((value ,(value->text value))))) - ((_key . value) - (if (string=? type "checkbox") - (if value - '((checked #t)) - '()) - `((value ,(value->text value))))))))) - ,@(if show-help-span? - `((span (@ (id ,help-span-id) - (class "help-block")) - ,@(if has-error? - (let* ((val - (assq-ref query-parameters - (string->symbol input-name))) - (messages - (map invalid-query-parameter-message - (if (list? val) - val - (list val))))) - `((p - ,@(if (null? messages) - '(string "Error: invalid value") - (map - (lambda (message) - `(strong - (@ (style "display: block;")) - ,(string-append - "Error: " message))) - messages))))) - '()) - ,@(if required? '((strong "Required. ")) '()) - ,@(if help-text - (list help-text) - '()))) - '()))))) + (map (match-lambda + ((option-label . option-value) + `(option + (@ ,@(if (member (if (and + (string? option-value) + (string=? option-value + null-string-value)) + "" + option-value) + selected-options) + '((selected "")) + '()) + (value ,option-value)) + ,(value->text option-label))) + (option-value + `(option + (@ ,@(if (member (if (and + (string? option-value) + (string=? option-value + null-string-value)) + "" + option-value) + selected-options) + '((selected "")) + '())) + ,(value->text option-value)))) + options))) + `(input (@ (class "form-control") + (style ,(if font-family + (string-append + "font-family: " font-family ";") + "")) + (id ,input-id) + (type ,type) + ,@(if required? + '((required #t)) + '()) + ,@(if show-help-span? + `((aria-describedby ,help-span-id)) + '()) + (name ,input-name) + ,@(match (assq (string->symbol input-name) + query-parameters) + (#f '()) + ((_key . ($ <invalid-query-parameter> value)) + (if (string=? type "checkbox") + (if value + '((checked #t)) + '()) + `((value ,(value->text value))))) + ((_key . value) + (if (string=? type "checkbox") + (if value + '((checked #t)) + '()) + `((value ,(value->text value))))))))) + ,@(if show-help-span? + `((span (@ (id ,help-span-id) + (class "help-block")) + ,@(if has-error? + (let* ((val + (assq-ref query-parameters + (string->symbol input-name))) + (messages + (map invalid-query-parameter-message + (if (list? val) + val + (list val))))) + `((p + ,@(if (null? messages) + '(string "Error: invalid value") + (map + (lambda (message) + `(strong + (@ (style "display: block;")) + ,(string-append + "Error: " message))) + messages))))) + '()) + ,@(if required? '((strong "Required. ")) '()) + ,@(if help-text + (list help-text) + '()))) + '())))))) (define (readme contents) (layout |