66 lines
3.7 KiB
HTML
66 lines
3.7 KiB
HTML
|
<div class="row">
|
||
|
<div class="row-item small-full small-text-center medium-third medium-text-right">
|
||
|
<label for="{{- .Get "id" -}}">{{- .Get "label" -}}</label>
|
||
|
</div>
|
||
|
<div class="row-item small-full small-text-center medium-two-thirds medium-text-left">
|
||
|
{{- $types := slice "color" "date" "datetime-local" "email" "file" "hidden" "month" "number" "password" "range" "tel" "text" "time" "url" "week" "textarea" -}}
|
||
|
{{- $type := .Get "type" -}}
|
||
|
{{- $id := .Get "id" -}}
|
||
|
{{- $name := (.Get "name" | default $id) -}}
|
||
|
{{- $placeholder := (.Get "placeholder" | default "") -}}
|
||
|
{{- $minlen := (.Get "minlength" | default "") -}}
|
||
|
{{- $maxlen := (.Get "maxlength" | default "") -}}
|
||
|
{{- $regex := (.Get "regex" | default "") -}}
|
||
|
{{- $value := (.Get "value" | default "") -}}
|
||
|
|
||
|
{{- if gt (len (findRE "([^a-zA-Z0-9_\\-\\.])+" $id 1)) 0 -}}
|
||
|
{{- errorf "ID \"%s\" should not contains characters other than ASCII letters, digits, '_', '-', and '.'" $id -}}
|
||
|
{{- else if not (in $types $type) -}}
|
||
|
{{- if or (eq $type "checkbox") (eq $type "radio") -}}
|
||
|
{{- errorf "To use input type \"%s\", use the mult-input shortcode instead." $type -}}
|
||
|
{{- else -}}
|
||
|
{{- errorf "Input type \"%s\" for ID \"%s\" is invalid/not allowed.\nValid values are: " $type $id (delimit $types ", ") -}}
|
||
|
{{- end -}}
|
||
|
{{- else if ne (len (findRE "^(\\d)*$" $minlen)) 1 -}}
|
||
|
{{- errorf "Minimum length \"%s\" must be a whole number!" $minlen -}}
|
||
|
{{- else if ne (len (findRE "^(\\d)*$" $maxlen)) 1 -}}
|
||
|
{{- errorf "Maximum length \"%s\" must be a whole number!" $maxlen -}}
|
||
|
{{- end -}}
|
||
|
|
||
|
{{- $.Scratch.Set "optional-tags" "" -}}
|
||
|
{{- with $placeholder -}}{{- $.Scratch.Add "optional-tags" (add (add " placeholder=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- with $regex -}}{{- $.Scratch.Add "optional-tags" (add (add " pattern=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- with $value -}}{{- $.Scratch.Add "optional-tags" (add (add " value=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- with $minlen -}}{{- $.Scratch.Add "optional-tags" (add (add " minlength=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- with $maxlen -}}{{- $.Scratch.Add "optional-tags" (add (add " maxlength=\"" .) "\"") -}}{{- end -}}
|
||
|
|
||
|
{{- if or (or (eq $type "number") (eq $type "date")) (eq $type "range") -}}
|
||
|
{{- $min := (.Get "min" | default "") -}}
|
||
|
{{- $max := (.Get "max" | default "") -}}
|
||
|
{{- $step := (.Get "step" | default "") -}}
|
||
|
{{- with $min -}}{{- $.Scratch.Add "optional-tags" (add (add " min=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- with $max -}}{{- $.Scratch.Add "optional-tags" (add (add " max=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- with $step -}}{{- $.Scratch.Add "optional-tags" (add (add " step=\"" .) "\"") -}}{{- end -}}
|
||
|
{{- else if eq $type "file" -}}
|
||
|
{{- $accepts := .Get "accept" -}}
|
||
|
{{- $.Scratch.Add "optional-tags" (add (add " accept=\"" $accepts) "\"") -}}
|
||
|
{{- else if or (eq $type "file") (eq $type "email") -}}
|
||
|
{{- if eq (.Get "multiple") "true" -}}
|
||
|
{{- $.Scratch.Add "optional-tags" " multiple" -}}
|
||
|
{{- end -}}
|
||
|
{{- end -}}
|
||
|
|
||
|
{{- if eq (.Get "required") "true" -}}
|
||
|
{{- $.Scratch.Add "optional-tags" " required" -}}
|
||
|
{{- end -}}
|
||
|
|
||
|
{{- if eq $type "textarea" -}}
|
||
|
<textarea id="{{ $id }}" name="{{ $id }}" rows="10"{{ ($.Scratch.Get "optional-tags" | safeHTMLAttr) }}></textarea>
|
||
|
{{- else if (in $types $type) -}}
|
||
|
<input type="{{ $type }}" id="{{ $id }}" name="{{ $id }}"{{ ($.Scratch.Get "optional-tags" | safeHTMLAttr) }} />
|
||
|
{{- else -}}
|
||
|
{{ errorf "If you are seeing this, please let the developer know at https://gitlab.com/BluestNight/BluestNight/issues\nInvalid input type \"%s\"" $type }}
|
||
|
{{- end -}}
|
||
|
</div>
|
||
|
</div>
|