6.1.4 Survey Tools
| (require conscript/survey-tools) | package: conscript |
The bindings in this module are also provided by conscript/base.
procedure
(refresh-every n-seconds) → xexpr?
n-seconds : exact-positive-integer?
> (define price 1.045) > (~$ price) "$1.04"
> (~euro price) "€1.04"
> (~pound price) "£1.04"
> (~$ 8) "$8.00"
procedure
(round-to-places num p) → real?
num : real? p : real?
If p is not an exact integer, it will be rounded to an exact integer to determine the number of decimal places for rounding. If p is zero, the result is the same as (round num). If it is less than zero, the result will be zero.
> (round-to-places 3.14159 2) 3.14
> (round-to-places 3.5 0) 4.0
> (round-to-places 4.5 0) 4.0
> (round-to-places 1.23 -1) 0.0
> (round-to-places 8 2) 8.0
value
Include this in a step that has a container element with class diceroll. Inside that container, place an <a> element with class button (the roll button) and an <output> element (where the result will be displayed). When the button is clicked, a random number from 1 to 6 is generated and displayed in the output element.
(defstep (roll-dice) @md{# Roll the Dice @diceroll-js @div[#:class "diceroll"]{ @a[#:class "button" #:href ""]{Roll} @output{}} @button{Continue}})
Include the result of calling this function in a step that has one or more container elements with class slider. Each container should have an <input type="range"> element and an <output> element. As the user moves the slider, the current value is automatically displayed in the output element.
This function is typically used internally by the make-sliders macro, but can be used directly when building custom slider interfaces.
procedure
n : exact-positive-integer?
The timer counts down and displays the remaining time as "X seconds left" (or "Y minutes and Z seconds left" for times over 60 seconds). When the timer reaches zero, it automatically submits any form on the page, or clicks the next button if no form is present.
(defstep (timed-task) @md{# Complete the task You have 60 seconds to complete this task. @timer[60] @form{...}})
syntax
(assigning-treatments arg)
arg : any/c
procedure
(is-equal expected [#:message message])
→ (-> any/c (or/c (cons/c 'ok any/c) (cons/c 'err string?))) expected : any/c message : (or/c #f string?) = #f
If the value equals expected, validation passes. Otherwise, validation fails with message (or a default message like "Should be equal to expected" if message is #f).
This is useful for creating quiz-like forms where there’s a specific correct answer:
(radios '(("a" . "Option A") ("b" . "Option B") ("c" . "Option C")) #:validators (list (is-equal "c" #:message "That's not correct, try again!")))
procedure
(make-multiple-checkboxes options [ #:n num-required #:exactly-n? exactly-n?] #:message message) → formular-field? options : (listof (cons/c symbol? string?)) num-required : exact-nonnegative-integer? = 0 exactly-n? : boolean? = #f message : (or/c #f string?)
See How to have a form input with multiple checkboxes for more examples of this function in use.
Returns a field containing multiple checkboxes defined by the options list. The num-required argument specifies the minimum number of checkboxes the user must check before they can submit the form. If message is not #f, it will be shown to the participant if they don’t check at least num-required boxes.
When #:exactly-n? is #t, the user is expected to check exactly n checkboxes, otherwise they get a validation error.
syntax
(make-sliders n maybe-widget-proc)
maybe-widget-proc =
| widget-proc-expr
n : exact-positive-integer?
widget-proc-expr : (-> exact-nonnegative-integer? formular-field?)
This macro generates a complete form with n range input sliders, each wrapped in a container with a live-updating value display. The form includes a submit button.
If widget-proc-expr is provided, it should be a procedure that takes a slider index (starting from 0) and returns a formular-field?. By default, each slider is created using input-range.
; Create a form with 3 default sliders (make-sliders 3) ; Create a form with custom slider ranges (make-sliders 5 (lambda (idx) (input-range #:min 0 #:max 100 #:step 5)))
procedure
(toggleable-xexpr message xexpr [ #:hidden? hidden?]) → xexpr? message : string? xexpr : xexpr? hidden? : boolean? = #t
The message argument is displayed as the button text. Clicking the button shows or hides the content specified by xexpr.
When hidden? is #t (the default), the content starts hidden and must be clicked to reveal. When hidden? is #f, the content starts visible.
(defstep (instructions) @md{# Task Overview @toggleable-xexpr["Show/Hide Detailed Instructions" @md*{## Detailed Instructions 1. First, do this... 2. Then, do that...}] @button{Continue}})