Add payload from field keys
This commit is contained in:
parent
047a1ad5e2
commit
57b4ce7c95
12
index.html
12
index.html
|
@ -10,12 +10,12 @@
|
||||||
style="--primary: hsl(181, 75%, 26%); --secondary: hsl(181, 75%, 35%); --font: hsl(181, 84%, 78%); --circle: hsl(181, 86%, 16%)"
|
style="--primary: hsl(181, 75%, 26%); --secondary: hsl(181, 75%, 35%); --font: hsl(181, 84%, 78%); --circle: hsl(181, 86%, 16%)"
|
||||||
value='{"sections": [
|
value='{"sections": [
|
||||||
{"name": "Personal", "intro": "Jaöaöd", "fields": [
|
{"name": "Personal", "intro": "Jaöaöd", "fields": [
|
||||||
{"name": "Vorname", "type": "TextField", "columns": {"mobile": 2, "tablet": 2, "desktop": 3}, "default": "", "required": true},
|
{"key": "vorname", "name": "Vorname", "type": "TextField", "columns": {"mobile": 2, "tablet": 2, "desktop": 3}, "default": "", "required": true},
|
||||||
{"name": "Essen", "type": "CheckboxesField", "columns": {"mobile": 2, "tablet": 2, "desktop": 3}, "default": [], "required": true, "options": ["lal", "fff", "ccc"]},
|
{"key": "essen", "name": "Essen", "type": "CheckboxesField", "columns": {"mobile": 2, "tablet": 2, "desktop": 3}, "default": [], "required": true, "options": ["lal", "fff", "ccc"]},
|
||||||
{"name": "Datenschutz", "description": "Ich akzeptire das abfghg", "type": "CheckboxField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": false, "required": true},
|
{"key": "datenschutz", "name": "Datenschutz", "description": "Ich akzeptire das abfghg", "type": "CheckboxField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": false, "required": true},
|
||||||
{"name": "Geschlecht", "type": "DropdownField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": null, "required": true, "options": ["A","Bb","Cc"]},
|
{"key": "geschlecht", "name": "Geschlecht", "type": "DropdownField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": null, "required": true, "options": ["A","Bb","Cc"]},
|
||||||
{"name": "Essgewohnheiten", "type": "RadioField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": null, "required": true, "options": ["A","Bb","Cc"]},
|
{"key": "essg", "name": "Essgewohnheiten", "type": "RadioField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": null, "required": true, "options": ["A","Bb","Cc"]},
|
||||||
{"name": "Nachname", "type": "TextField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": "", "required": true}
|
{"key": "nachn", "name": "Nachname", "type": "TextField", "columns": {"mobile": 2, "tablet": 3, "desktop": 6}, "default": "", "required": true}
|
||||||
]},
|
]},
|
||||||
{"name": "Veranstaltung", "intro": "Jaöaöd", "fields": [
|
{"name": "Veranstaltung", "intro": "Jaöaöd", "fields": [
|
||||||
]},
|
]},
|
||||||
|
|
37
package.json
37
package.json
|
@ -1,21 +1,20 @@
|
||||||
{
|
{
|
||||||
"name": "eventform",
|
"name": "eventform",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vue": "^3.3.11"
|
"vue": "^3.3.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/container-queries": "^0.1.1",
|
"@tailwindcss/container-queries": "^0.1.1",
|
||||||
"@vitejs/plugin-vue": "^4.5.2",
|
"@vitejs/plugin-vue": "^4.5.2",
|
||||||
"change-case": "^5.3.0",
|
"vite": "^5.0.8",
|
||||||
"vite": "^5.0.8",
|
"vue3-carousel": "^0.3.1"
|
||||||
"vue3-carousel": "^0.3.1"
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import {computed, ref} from 'vue';
|
import {computed, ref} from 'vue';
|
||||||
import {Carousel, Slide} from 'vue3-carousel';
|
import {Carousel, Slide} from 'vue3-carousel';
|
||||||
import {camelCase} from 'change-case';
|
|
||||||
import Navigation from './components/Navigation.vue';
|
import Navigation from './components/Navigation.vue';
|
||||||
import useNav from './composables/useNav.js';
|
import useNav from './composables/useNav.js';
|
||||||
import FieldText from './components/fields/Text.vue';
|
import FieldText from './components/fields/Text.vue';
|
||||||
|
@ -184,14 +183,25 @@ const props = defineProps({
|
||||||
fields: {},
|
fields: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
const finished = ref(false);
|
|
||||||
const active = ref(0);
|
const active = ref(0);
|
||||||
const payload = ref({});
|
const payload = ref({});
|
||||||
const loaded = ref(false);
|
const loaded = ref(false);
|
||||||
|
|
||||||
const v = computed(() => JSON.parse(props.value));
|
const v = computed(() => {
|
||||||
|
loaded.value = false;
|
||||||
|
var values = JSON.parse(props.value);
|
||||||
|
var p = {};
|
||||||
|
|
||||||
|
values.sections.forEach(function (section) {
|
||||||
|
section.fields.forEach(function (field) {
|
||||||
|
p[field.key] = field.default;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
payload.value = p;
|
||||||
|
loaded.value = true;
|
||||||
|
return values;
|
||||||
|
});
|
||||||
const f = computed(() => JSON.parse(props.fields));
|
const f = computed(() => JSON.parse(props.fields));
|
||||||
const addingFields = ref(false);
|
|
||||||
|
|
||||||
const {back, next, backable, nextable} = useNav(active, v.value.sections.length);
|
const {back, next, backable, nextable} = useNav(active, v.value.sections.length);
|
||||||
|
|
||||||
|
@ -206,26 +216,7 @@ function resolveComponentName(field) {
|
||||||
}[field.type];
|
}[field.type];
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateDefaultValues() {
|
|
||||||
payload.value = {};
|
|
||||||
v.value.sections = v.value.sections.map(function (section) {
|
|
||||||
return {
|
|
||||||
...section,
|
|
||||||
fields: section.fields.map(function (field) {
|
|
||||||
payload.value[camelCase(field.name)] = field.default;
|
|
||||||
return {
|
|
||||||
...field,
|
|
||||||
key: camelCase(field.name),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
console.log(payload.value);
|
console.log(payload.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateDefaultValues();
|
|
||||||
loaded.value = true;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -6,10 +6,9 @@
|
||||||
<span class="border-neutral-400 border-4 border-solid peer-checked:border-primary absolute left-0 w-6 h-6 rounded block"></span>
|
<span class="border-neutral-400 border-4 border-solid peer-checked:border-primary absolute left-0 w-6 h-6 rounded block"></span>
|
||||||
<span class="peer-checked:bg-primary left-2 w-2 h-2 absolute rounded block"></span>
|
<span class="peer-checked:bg-primary left-2 w-2 h-2 absolute rounded block"></span>
|
||||||
<span class="pl-8 text-gray-600 text-sm @sm:text-base" v-text="field.description"></span>
|
<span class="pl-8 text-gray-600 text-sm @sm:text-base" v-text="field.description"></span>
|
||||||
|
<span v-show="field.required" class="text-red-800 ml-1">*</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<field-label :name="field.name" :required="field.required" inline></field-label>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue