Skip to content

Commit 0afe6fc

Browse files
committed
feat(reset): Add reset to FormKitDataEdit component
1 parent c1eb176 commit 0afe6fc

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

dev/pages/data/Edit.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { addElement } = useFormKitSchema()
66
const { t } = useI18n()
77
const horizontal = ref(false)
88
const indentCheckboxes = ref(false)
9+
const showReset = ref(false)
910
1011
const options = [
1112
{ label: 'Every page load', value: 'refresh' },
@@ -100,12 +101,14 @@ async function submitHandler() {
100101
<template>
101102
<PrimeData header="FormKitDataEdit Demo">
102103
<div class="flex gap-2 mb-4">
104+
<div>Show Reset Button</div>
105+
<Checkbox v-model="showReset" binary />
103106
<div>Horizontal</div>
104-
<ToggleSwitch v-model="horizontal" />
107+
<Checkbox v-model="horizontal" binary />
105108
<div v-if="horizontal">
106109
Indent Checkboxes
107110
</div>
108-
<ToggleSwitch v-if="horizontal" v-model="indentCheckboxes" />
111+
<Checkbox v-if="horizontal" v-model="indentCheckboxes" binary />
109112
</div>
110113
<FormKitDataEdit
111114
:data="data"
@@ -114,6 +117,7 @@ async function submitHandler() {
114117
:form-class="(horizontal ? ' form-horizontal' : '') + (indentCheckboxes ? ' form-horizontal-checkbox-indent ' : '')"
115118
:debug-data="true"
116119
:debug-schema="true"
120+
:show-reset="showReset"
117121
@data-saved="submitHandler"
118122
/>
119123
</PrimeData>

src/components/FormKitDataEdit.vue

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<script setup lang='ts'>
22
import type { FormKitSchemaDefinition } from '@formkit/core'
33
import type { PropType } from 'vue'
4+
import { reset } from '@formkit/core'
45
import { FormKit, FormKitMessages, FormKitSchema } from '@formkit/vue'
56
import { ref } from 'vue'
67
import FormKitDebug from './FormKitDebug.vue'
78
89
const props = defineProps({
910
id: {
1011
type: String,
11-
default: 'form',
12+
default: 'formkit_form',
1213
},
1314
data: {
1415
type: Object,
@@ -18,38 +19,58 @@ const props = defineProps({
1819
type: Object as PropType<FormKitSchemaDefinition>,
1920
default: null,
2021
},
21-
debugData: {
22-
type: Boolean,
23-
default: false,
22+
formClass: {
23+
type: String,
24+
default: '',
2425
},
25-
debugSchema: {
26-
type: Boolean,
27-
default: false,
26+
actionsClass: {
27+
type: String,
28+
default: '',
2829
},
29-
inputClass: {
30+
submitSeverity: {
3031
type: String,
31-
default: 'p-button p-component p-formkit-button',
32+
default: '',
33+
},
34+
submitClass: {
35+
type: String,
36+
default: '',
3237
},
3338
submitLabel: {
3439
type: String,
3540
default: 'Save',
3641
},
37-
cancelLabel: {
42+
submitIcon: {
3843
type: String,
39-
default: 'Cancel',
44+
default: '',
4045
},
41-
formClass: {
46+
showReset: {
47+
type: Boolean,
48+
default: false,
49+
},
50+
resetSeverity: {
4251
type: String,
43-
default: '',
52+
default: 'danger',
4453
},
45-
actionsClass: {
54+
resetLabel: {
55+
type: String,
56+
default: 'Reset',
57+
},
58+
resetClass: {
4659
type: String,
4760
default: '',
4861
},
49-
buttonClass: {
62+
resetIcon: {
5063
type: String,
5164
default: '',
5265
},
66+
debugData: {
67+
type: Boolean,
68+
default: false,
69+
},
70+
debugSchema: {
71+
type: Boolean,
72+
default: false,
73+
},
5374
})
5475
5576
const emit = defineEmits(['dataSaved'])
@@ -60,6 +81,10 @@ const formData = ref(props.data)
6081
function handleSave() {
6182
emit('dataSaved', props.data)
6283
}
84+
85+
function handleReset() {
86+
reset(props.id)
87+
}
6388
</script>
6489

6590
<template>
@@ -83,7 +108,8 @@ function handleSave() {
83108
</template>
84109
<template #submit>
85110
<slot name="submit">
86-
<Button type="submit" :label="submitLabel" :class="buttonClass" @submit="handleSave" />
111+
<Button :icon="submitIcon" type="submit" :label="submitLabel" :class="submitClass" :severity="submitSeverity" @submit="handleSave" />
112+
<Button v-if="showReset" type="reset" :icon="resetIcon" :label="resetLabel" :class="resetClass" :severity="resetSeverity" @click="handleReset" />
87113
</slot>
88114
</template>
89115
</FormKit>

src/sass/formkit-primevue.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ $grid-breakpoints: (
147147
// Submit button etc.
148148
.formkit-actions {
149149
padding-top: 0.5rem;
150+
display: flex;
151+
button {
152+
margin-right: 0.5rem;
153+
}
154+
150155
}
151156

152157
.p-action-buttons {

0 commit comments

Comments
 (0)