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

Commit 4e73a6e

Browse files
committed
Preparing the library
1 parent e268609 commit 4e73a6e

File tree

12 files changed

+4361
-1598
lines changed

12 files changed

+4361
-1598
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

README.md

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ Easy way to dynamically create reactive forms in vue based on varying business o
1818

1919
Complete documentation and examples available at
2020

21-
- **[API Documentation]()**
22-
- **[Sandbox Demo]()**
23-
- **[CodePen Template]()**
24-
- **[GitHub Projects]()**
21+
- **[API Documentation]()** (soon)
22+
- **[Sandbox Demo]()** (soon)
2523

26-
## Install
24+
## Installation
2725

2826
```bash
2927
$ npm install @asigloo/vue-dynamic-forms
@@ -35,7 +33,11 @@ or if you prefer yarn
3533
$ yarn add @asigloo/vue-dynamic-forms
3634
```
3735

38-
Register the component
36+
## Usage
37+
38+
### Global
39+
40+
Register the component globally in your `main.js`:
3941

4042
```js
4143
import Vue from 'vue';
@@ -44,6 +46,63 @@ import VueDynamicForms from '@asigloo/vue-dynamic-forms';
4446
Vue.use(VueDynamicForms);
4547
```
4648

49+
### Local
50+
51+
You can include the dynamic form directly to your component.
52+
53+
```js
54+
import Vue from 'vue';
55+
import { DynamicForm } from '@asigloo/vue-dynamic-forms';
56+
57+
const components = { DynamicForm };
58+
59+
export {
60+
...
61+
components,
62+
...
63+
}
64+
```
65+
66+
### Form Composition
67+
68+
The dynamic form component is really easy to use, you will only need to add it to your template like this:
69+
70+
```html
71+
<template>
72+
<dynamic-form :id="testForm.id" :fields="testForm.fields" />
73+
</template>
74+
```
75+
76+
And then create the fields on your component's data structure, to create the fields you can import the factory function `FormField` from the library core:
77+
78+
```js
79+
import { FormField } from '@asigloo/vue-dynamic-forms';
80+
81+
const yourAwesomeComponent = {
82+
name: 'your-awesome',
83+
data() {
84+
return {
85+
testForm: {
86+
id: 'test-form',
87+
fields: [
88+
new FormField({
89+
type: 'text',
90+
label: 'Name',
91+
name: 'name',
92+
}),
93+
],
94+
},
95+
};
96+
},
97+
};
98+
99+
export default yourAwesomeComponent;
100+
```
101+
102+
### Styling themes
103+
104+
The components are unstyled by default, so you can customize them with your own styles. If you want a more "ready to go" solution you can import on of the themes we have included
105+
47106
## Development
48107

49108
### Project setup

dev/App.vue

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
</template>
2626

2727
<script>
28-
import { email, required, pattern } from '../src/core/utils/validators';
29-
import { FormField } from '../src/core/utils/form-control.model';
30-
31-
const DynamicForm = () => import('@/components/dynamic-form/DynamicForm.vue');
28+
import {
29+
FormField,
30+
FormValidation,
31+
required,
32+
email,
33+
pattern,
34+
/* } from '../dist/as-dynamic-forms.common'; */
35+
} from '../src/main';
3236
3337
const data = () => ({
3438
formData: {},
@@ -45,34 +49,32 @@ const data = () => ({
4549
label: 'Email',
4650
name: 'email',
4751
validations: [
48-
{ validator: required, text: 'This field is required' },
49-
{ validator: email, text: 'Format of email is incorrect' },
52+
new FormValidation(required, 'This field is required'),
53+
new FormValidation(email, 'Format of email is incorrect'),
5054
],
5155
}),
5256
new FormField({
5357
type: 'password',
5458
label: 'Password',
5559
name: 'password',
56-
/* validations: [
57-
required,
58-
pattern(
59-
'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&]).{8,10}$',
60+
validations: [
61+
new FormValidation(required, 'This field is required'),
62+
new FormValidation(
63+
pattern(
64+
'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&]).{8,10}$',
65+
),
66+
'Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10',
6067
),
61-
], */
68+
],
69+
6270
value: 'sdsdsd',
63-
/* errorTexts: [
64-
'This field is required',
65-
'Password must contain at least 1 Upercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10',
66-
], */
6771
}),
6872
new FormField({
6973
type: 'textarea',
7074
label: 'Bio',
7175
name: 'bio',
7276
cols: 30,
7377
rows: 5,
74-
/* validations: [required],
75-
errorTexts: ['This field is required'], */
7678
}),
7779
new FormField({
7880
type: 'select',
@@ -89,14 +91,11 @@ const data = () => ({
8991
label: 'Read the conditions',
9092
name: 'conditions',
9193
inline: false,
92-
/* validations: [required],
93-
errorTexts: ['This field is required'], */
9494
}),
9595
new FormField({
9696
type: 'radio',
9797
label: 'Prefered Animal',
9898
name: 'animal',
99-
/* validations: [], */
10099
inline: true,
101100
options: [
102101
{ text: 'Dogs', value: 'dogs' },
@@ -109,17 +108,11 @@ const data = () => ({
109108
label: 'Number',
110109
name: 'number',
111110
value: 0,
112-
/* validations: [required],
113-
errorTexts: ['This field is required'], */
114111
}),
115112
],
116113
},
117114
});
118115
119-
const components = {
120-
DynamicForm,
121-
};
122-
123116
const methods = {
124117
valuesChanged(values) {
125118
this.$forceUpdate(); // this is only to refresh the fields on the <pre> tags, not necessary for other purpouses
@@ -134,9 +127,6 @@ const methods = {
134127
export default {
135128
name: 'app',
136129
data,
137-
components,
138130
methods,
139131
};
140132
</script>
141-
142-
<style lang="scss"></style>

dev/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import Vue from 'vue';
22
import App from './App.vue';
33
import './styles/main.scss';
4-
4+
/* import VueDynamicForms from '../dist/as-dynamic-forms.common';
5+
*/
6+
import VueDynamicForms from '../src/main';
57
Vue.config.productionTip = false;
8+
Vue.use(VueDynamicForms);
69

710
new Vue({ render: h => h(App) }).$mount('#app');

0 commit comments

Comments
 (0)