aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/web/view
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-12-01 21:23:25 +0000
committerChristopher Baines <mail@cbaines.net>2019-12-12 20:01:26 +0000
commit04e98ed4da6ad82d71db048b11a31f52dc89c0e4 (patch)
tree24d9be8ea28ad2a741781fb24b6e74a3801c8c66 /guix-data-service/web/view
parent7cc5c02cdd4b367f81861dfdf172da95b6481696 (diff)
downloaddata-service-04e98ed4da6ad82d71db048b11a31f52dc89c0e4.tar
data-service-04e98ed4da6ad82d71db048b11a31f52dc89c0e4.tar.gz
Handle multiple invalid values for a single form field
Diffstat (limited to 'guix-data-service/web/view')
-rw-r--r--guix-data-service/web/view/html.scm35
1 files changed, 23 insertions, 12 deletions
diff --git a/guix-data-service/web/view/html.scm b/guix-data-service/web/view/html.scm
index 487954f..1417505 100644
--- a/guix-data-service/web/view/html.scm
+++ b/guix-data-service/web/view/html.scm
@@ -122,9 +122,12 @@
(input-name (or name
(underscore-join-words
(string-downcase label))))
- (has-error? (invalid-query-parameter?
- (assq-ref query-parameters
- (string->symbol input-name))))
+ (has-error? (let ((val
+ (assq-ref query-parameters
+ (string->symbol input-name))))
+ (if (list? val)
+ (any invalid-query-parameter? val)
+ (invalid-query-parameter? val))))
(show-help-span?
(or help-text has-error? required?)))
`(div
@@ -204,16 +207,24 @@
`((span (@ (id ,help-span-id)
(class "help-block"))
,@(if has-error?
- (let ((message
- (invalid-query-parameter-message
+ (let* ((val
(assq-ref query-parameters
- (string->symbol input-name)))))
- `((p (strong
- ,(string-append
- "Error: "
- (if message
- message
- "invalid value."))))))
+ (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