Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 249fbc4

Browse files
authored
Merge pull request #19 from alvarosaburido/feature/spread_options
Added Spread Form Options and netlify support
2 parents 71b6a9c + 705a7cb commit 249fbc4

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

dev/App.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<dynamic-form
88
:id="testForm.id"
99
:fields="testForm.fields"
10-
:customClass="'row'"
10+
:options="testForm.options"
1111
@change="valuesChanged"
1212
>
1313
<template slot="custom-field-1" slot-scope="props">
@@ -149,6 +149,10 @@ const data = () => ({
149149
customClass: 'col-12 col-md-6',
150150
}),
151151
],
152+
options: {
153+
customClass: 'row',
154+
netlify: true,
155+
},
152156
},
153157
});
154158

src/components/dynamic-form/DynamicForm.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FormControl } from '@/core/utils';
1+
import { FormControl, FormOptions } from '@/core/utils';
22

33
import DynamicInput from '@/components/dynamic-input/DynamicInput.vue';
44

@@ -17,17 +17,13 @@ const props = {
1717
default: null,
1818
type: String,
1919
},
20-
method: {
21-
default: 'POST',
22-
type: String,
23-
},
24-
customClass: {
25-
default: null,
26-
type: String,
27-
},
2820
fields: {
2921
type: Array,
3022
},
23+
options: {
24+
type: Object,
25+
default: () => new FormOptions(),
26+
},
3127
};
3228

3329
const methods = {
@@ -111,6 +107,17 @@ const computed = {
111107
}, {})
112108
: {};
113109
},
110+
formattedOptions() {
111+
const { customClass, method, netlify, netlifyHoneyPot } = new FormOptions(
112+
this.options,
113+
);
114+
return {
115+
class: customClass,
116+
method,
117+
'data-netlify': netlify,
118+
'data-netlify-honeypot': netlifyHoneyPot,
119+
};
120+
},
114121
deNormalizedScopedSlots() {
115122
return Object.keys(this.$scopedSlots);
116123
},

src/components/dynamic-form/DynamicForm.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
v-if="fields.length > 0 && !showFeedback"
55
:id="id"
66
:name="id"
7-
:class="customClass"
8-
:method="method"
7+
v-bind="formattedOptions"
98
novalidate
109
@submit.prevent="handleSubmit()"
1110
>

src/core/utils/form-control.model.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ export function FormValidation(
5858
this.text = text;
5959
}
6060

61-
export default { FormControl, FormField, FormValidation };
61+
export function FormOptions({
62+
customClass = '',
63+
method = 'POST',
64+
netlify = false,
65+
netlifyHoneypot = null,
66+
}) {
67+
this.customClass = customClass;
68+
this.method = method;
69+
this.netlify = netlify;
70+
this.netlifyHoneypot = netlifyHoneypot;
71+
}
72+
73+
export default { FormControl, FormField, FormValidation, FormOptions };

0 commit comments

Comments
 (0)