bunteshaus.de/themes/buha/layouts/partials/layout/single/generator/form.html

143 lines
8.1 KiB
HTML

{{ $pageform := (index .context.Page.Params.forms .form) }}
{{ $group := slice }}
{{ $divide := .context.Page.Params.divide }}
<form id="myform">
{{ range $pageform.fields }}
{{ $title := .title }}
{{ $name := $title }}
{{ if .name }}
{{ $name = .name }}
{{ 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 "layout/single/generator/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 }}>{{- $name -}}{{- if .required -}}{{- " *" -}}{{- end -}}</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.names }}sr-only{{ end }} for="{{ .title }}">{{- $name -}}{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<textarea name="{{ .title }}" id="{{ .title }}" rows="10" {{ if $pageform.names }}placeholder="{{ .name }}{{ .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="{{ .title }}" id="{{ .title }}" value="{{ .name }}" {{ .Scratch.Get "requiredtext" }}>{{- $name -}}{{- if .required -}}{{- " *" -}}{{- end -}}</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="{{ .title }}" id="{{ .title }}" value="{{ .name }}" {{ .Scratch.Get "requiredtext" }}>{{- $name -}}{{- if .required -}}{{- " *" -}}{{- 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; margin-top: 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="{{- $name -}}" onclick="showInput(event);" />
</div>
{{ else if eq .input_type "mc" }}
{{ $in0 := .title }}
{{- $finale := slice -}}
{{ $pages := where site.RegularPages "Type" "in" site.Params.searchSections }}
{{ if eq .title "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 }}">
{{ .name }}
{{ if ne .expanded true }}{{ partial "layout/single/generator/expand" (dict "name" (printf "%scat" $in0)) }}{{ end }}{{- if .required -}}{{- " *" -}}{{- 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 .new }}
<label id="label" for="new{{- .title -}}">{{ .new }} <span style="font-size: x-small;">({{ $divide }})</span></label>
<input type="text" name="new{{- .title -}}" id="new{{- .title -}}" value="" placeholder="{{ .eg }}" />
{{ end }}
</div>
</div>
</div>
{{ else }}
{{ if eq .title "name" }}
<div class="half {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">
<label class="{{ if $pageform.names }}sr-only{{ end }}" for="firstname">First name{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<input type="text" name="firstname" id="firstname" {{ if $pageform.names }}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.names }}sr-only{{ end }}" for="lastname">Last name{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<input type="text" name="lastname" id="lastname" {{ if $pageform.names }}placeholder="Last name{{ .Scratch.Get "requiredstar" }}"{{ end }} {{ .Scratch.Get "requiredtext" }}>
</div>
{{ else if eq .title "address" }}
<div {{- if .group }} class="visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'"{{ end -}}>
<label class="{{ if $pageform.names }}sr-only{{ end }}" for="address">Address{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<input type="text" name="address" id="address" {{ if $pageform.names }}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.names }}sr-only{{ end }}" for="city">City{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<input type="text" name="city" id="city" {{ if $pageform.names }}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.names }}sr-only{{ end }}" for="postalcode">Postal code{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<input type="text" name="postalcode" id="postalcode" {{ if $pageform.names }}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.names }}sr-only{{ end }}" for="{{ .title }}">{{ .name }}{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<input type="{{ .input_type }}" name="{{ .title }}" id="{{ .title }}" {{ if $pageform.names }}placeholder="{{ .name }}"{{ end }}>
</div>
</div>
{{ end }}
{{ end }}
{{ end }}
</form>