bunteshaus.de/themes/buha/layouts/partials/misc/form.html
2022-04-08 13:22:50 +02:00

142 lines
8.3 KiB
HTML

{{ $pageform := (index .context.Page.Params.forms .form) }}
{{ $group := slice }}
<form id="myform">
{{ range $pageform.fields }}
{{ if .required }}{{ .Scratch.Set "requiredstar" "" }}{{ else }}{{ .Scratch.Set "requiredstar" " (optioneel)" }}{{ end }}
{{ if .required }}{{ .Scratch.Set "requiredtext" "required" }}{{ else }}{{ .Scratch.Set "requiredtext" "" }}{{ end }}
{{ if and .group (not (in $group .group))}}
<div class="margin_top_1rem">
{{ if i18n (singularize .group) }}{{ i18n (singularize .group) }}{{ else }}{{ humanize .group }}{{ end }}
{{ partial "misc/expand" (dict "name" (printf "%sgroup" .group)) }}
</div>
{{ $group = $group | append .group }}
{{ end }}
{{ if eq .input_type "title" }}
<h3 {{ if .group }}class="visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'"{{ end }}>{{ .placeholder }}</h3>
{{ else if eq .input_type "textarea" }}
<div {{ if .group }}class="visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'"{{ end }}>
<label {{ if $pageform.placeholders }}sr-only{{ end }} for="{{ .name }}">{{ .placeholder }}{{ .Scratch.Get "requiredstar" }}</label>
<textarea name="{{ .name }}" id="{{ .name }}" rows="10" {{ if $pageform.placeholders }}placeholder="{{ .placeholder }}{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}></textarea>
</div>
{{ else if eq .input_type "radio" }}
<div class="radio {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<label><input type="radio" name="{{ .name }}" id="{{ .name }}" value="{{ .placeholder }}" {{ .Scratch.Get "requiredtext" }}>{{ .placeholder }}</label>
</div>
{{ else if eq .input_type "checkbox" }}
<div class="checkbox {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<label><input type="checkbox" name="{{ .name }}" id="{{ .name }}" value="{{ .placeholder }}" {{ .Scratch.Get "requiredtext" }}>{{ if i18n .placeholder }}{{ i18n .placeholder }}{{ else }}{{ humanize .placeholder }}{{ end }}</label>
</div>
{{ else if eq .input_type "results" }}
<div id='display' class="result" style="white-space: pre; display: none; background: var(--background-body); padding: .6rem 0 1rem 1rem;"></div>
{{ else if eq .input_type "submit" }}
<div class="margin_top_1rem {{ if .group }}visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<input type="{{ .input_type }}" value="{{ if i18n "generate" }}{{ i18n "generate" }}{{ else }}{{ "Generate" }}{{ end }}" onclick="showInput(event);" />
</div>
{{ else if eq .input_type "mc" }}
{{ $in0 := .name }}
{{- $finale := slice -}}
{{ $pages := where site.RegularPages "Type" "in" site.Params.searchSections }}
{{ if eq .name "tags" }}
{{ range $pages }}
{{- if .Params.tags -}}
{{- $finale = $finale | append .Params.tags -}}
{{ end }}
{{ end }}
{{ else }}
{{ range $pages }}
{{ range .Param $in0 }}
{{- $finale = $finale | append . -}}
{{ end }}
{{ end }}
{{ end }}
{{- $finale = $finale | uniq -}}
<div class="margin_top_1rem {{- if .group }} visibleIf" data-visibleif-rule="{{ .group }}group == 'true'"{{ else }}"{{ end }} style="flex-direction: column;">
<div class="{{- if .group }}margin_left_1rem{{ end }}">
{{ .placeholder }}
{{ if ne .expanded true }}{{ partial "misc/expand" (dict "name" (printf "%scat" $in0)) }}{{ end }}
</div>
<div class="checkbox {{ if ne .expanded true }}visibleIf" data-visibleif-rule="{{ $in0 }}cat == 'true'{{end}}">
<div class="{{- if .group }} margin_left_1rem{{ end }} minmax" style="display: flex; flex-direction: column;">
<fieldset id="{{ $in0 }}" name="{{ $in0 }}" style="display: flex; flex-direction: row; padding: 0; border: none; margin: 0 0 .3rem .5rem;">
{{ range sort $finale }}
<input type="checkbox" name="{{ $in0 }}" id="{{ $in0 }}-cat" value="{{ . }}"><label for="{{ $in0 }}-cat">{{ . }}</label>
{{ end }}
</fieldset>
{{ if eq .new true }}
<label id="label" for="new{{- .name -}}">{{ if i18n "new" }}{{ i18n "new" }}{{ else }}{{ "New" }}{{ end }} <span style="font-size: x-small;">(Getrennt durch Komma)</span></label>
<input type="text" name="new{{- .name -}}" id="new{{- .name -}}" value="" placeholder="{{ .eg }}" />
{{ end }}
</div>
</div>
</div>
{{ else }}
{{ if eq .name "name" }}
<div class="half {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<label class="{{ if $pageform.placeholders }}sr-only{{ end }}" for="firstname">First name{{ .Scratch.Get "requiredstar" }}</label>
<input type="text" name="firstname" id="firstname" {{ if $pageform.placeholders }}placeholder="First name{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
<div class="half {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<label class="{{ if $pageform.placeholders }}sr-only{{ end }}" for="lastname">Last name{{ .Scratch.Get "requiredstar" }}</label>
<input type="text" name="lastname" id="lastname" {{ if $pageform.placeholders }}placeholder="Last name{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
{{ else if eq .name "address" }}
<div {{- if .group }} class="visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'"{{ end -}}>
<label class="{{ if $pageform.placeholders }}sr-only{{ end }}" for="address">Address{{ .Scratch.Get "requiredstar" }}</label>
<input type="text" name="address" id="address" {{ if $pageform.placeholders }}placeholder="Address{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
<div class="half {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true{{ end }}">
<label class="{{ if $pageform.placeholders }}sr-only{{ end }}" for="city">City{{ .Scratch.Get "requiredstar" }}</label>
<input type="text" name="city" id="city" {{ if $pageform.placeholders }}placeholder="City{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
<div class="half {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<label class="{{ if $pageform.placeholders }}sr-only{{ end }}" for="postalcode">Postal code{{ .Scratch.Get "requiredstar" }}</label>
<input type="text" name="postalcode" id="postalcode" {{ if $pageform.placeholders }}placeholder="Postal code{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
{{ else }}
<div class="margin_top_1rem {{ if .group }} visibleIf margin_left_1rem" data-visibleif-rule=" {{ .group }}group == 'true' {{ end }}" class="minmax">
<div class="minmax" style="display: flex; flex-direction: column;">
<label class="{{ if $pageform.placeholders }}sr-only{{ end }}" for="{{ .name }}">{{ .placeholder }}{{ .Scratch.Get "requiredstar" }}</label>
<input type="{{ .input_type }}" name="{{ .name }}" id="{{ .name }}" {{ if $pageform.placeholders }}placeholder="{{ .placeholder }}{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
</div>
{{ end }}
{{ end }}
{{ end }}
</form>