Use a specific macro to generate a answer
This commit is contained in:
parent
2a5fa8126a
commit
8017094aa9
1 changed files with 11 additions and 8 deletions
|
@ -133,7 +133,13 @@ Example:
|
||||||
:aria-label "Search")
|
:aria-label "Search")
|
||||||
(btn-outline-success (:type "submit") "Search"))))
|
(btn-outline-success (:type "submit") "Search"))))
|
||||||
|
|
||||||
(defmacro question (question (&key (name "") (type "")) &rest rest)
|
(defmacro answer (text (&key name type))
|
||||||
|
`(spinneret:with-html
|
||||||
|
(:li (:label :class "form-label"
|
||||||
|
(:input :type ,type :name ,name)
|
||||||
|
,text))))
|
||||||
|
|
||||||
|
(defmacro question (question answers (&key (name "") (type "")))
|
||||||
"This macro generates a fieldset for a question with multiple answers.
|
"This macro generates a fieldset for a question with multiple answers.
|
||||||
|
|
||||||
QUESTION: The text of the question to be displayed in the legend.
|
QUESTION: The text of the question to be displayed in the legend.
|
||||||
|
@ -152,11 +158,10 @@ Example:
|
||||||
(:name \"age\" :type \"radio\") \"18-24\" \"25-34\" \"35-44\")"
|
(:name \"age\" :type \"radio\") \"18-24\" \"25-34\" \"35-44\")"
|
||||||
`(spinneret:with-html
|
`(spinneret:with-html
|
||||||
(:fieldset (:legend ,question)
|
(:fieldset (:legend ,question)
|
||||||
(:ol ,@(loop for answer in rest
|
(:ol ,@(loop for item in answers
|
||||||
collect `(:li (:label :class "form-label"
|
collect `(answer ,item (:name ,name :type ,type)))))))
|
||||||
(:input :type ,type :name ,name) ,answer)))))))
|
|
||||||
|
|
||||||
(defmacro questionnaire (action &rest rest)
|
(defmacro questionnaire (action &body body)
|
||||||
"This macro generates an HTML form composed of multiple questions, each
|
"This macro generates an HTML form composed of multiple questions, each
|
||||||
rendered using the `question` macro.
|
rendered using the `question` macro.
|
||||||
|
|
||||||
|
@ -176,7 +181,5 @@ This will create a form with two questions, each with radio button options, and
|
||||||
`(spinneret:with-html
|
`(spinneret:with-html
|
||||||
(:form :action ,action
|
(:form :action ,action
|
||||||
:method "post"
|
:method "post"
|
||||||
,@(loop for item in rest
|
,@body
|
||||||
collect (destructuring-bind (&key question name type answers) item
|
|
||||||
`(question ,question (:name ,name :type ,type) ,@answers)))
|
|
||||||
(btn-primary (:type "submit") "Submit"))))
|
(btn-primary (:type "submit") "Submit"))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue