From: Paul Hänsch Date: Fri, 22 Jun 2018 02:53:38 +0000 (+0200) Subject: experimental radio list X-Git-Url: http://git.plutz.net/?p=shcgi;a=commitdiff_plain;h=HEAD experimental radio list --- diff --git a/forms.sh b/forms.sh index 50cb204..69c7630 100755 --- a/forms.sh +++ b/forms.sh @@ -22,6 +22,7 @@ setopt -o OCTAL_ZEROES 2>&- form_radio(){ + # Produce a single radio button and an associated label # Usage: form_radio Name Value Condition Label # if "Condition" is the same as "Value", the button will be checked @@ -38,6 +39,7 @@ form_radio(){ } form_check(){ + # Produce a checkbox and an associated label # Usage: form_check Name Value Condition Label # if "Condition" is the same as "Value", the Checkbox will be checked @@ -52,3 +54,20 @@ form_check(){ printf '' \ "$id" "$name" "$value" "$check" "$id" "$label" } + +form_radio_list(){ + # Produce a group of radio buttons + # Buttons can be given in the form label/value either as parameters, + # or as lines on stdin + # if hte button value matches cond, this button will be selected + + name="$1" + cond="$2" + shift 2 + + if [ -n "$*" ]; then for each in "$@"; do + form_radio "$name" "${each##*/}" "$cond" "${each%/*}" + done; else while read each; do + form_radio "$name" "${each##*/}" "$cond" "${each%/*}" + done; fi +}