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

Commit 7c860c1

Browse files
committed
Merge branch 'feature/update_dependencies_and_readme' into develop
2 parents e268609 + 77be8f7 commit 7c860c1

25 files changed

+4681
-1681
lines changed

.eslintignore

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

.npmignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/templates
2+
.vuegenerator
3+
.eslintrc.js
4+
.eslintignore
5+
jest.config.js
6+
babel.config.js
7+
vue.config.js
8+
postcss.config.js
9+
.prettierrc
10+
yarn.lock
11+
/dev
12+
/docs
13+
/public
14+
/coverage
15+
/.vscode
16+
/tests

README.md

Lines changed: 241 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
![repository-banner.png](https://res.cloudinary.com/alvarosaburido/image/upload/v1564929632/as-readme-banner_tqdgrx.png)
22

3-
## Software version
4-
5-
- `node -v` : v12.4.0
6-
- `npm -v` : v6.4.1
7-
- `yarn -v`: 1.9.4
8-
- `vue --version`:3.0.3
9-
- `webpack -v` : v4.1.1
10-
113
# Vue Dynamic Forms
124

135
![Current Relase](https://img.shields.io/github/package-json/v/alvarosaburido/vue-dynamic-forms) [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
@@ -18,12 +10,10 @@ Easy way to dynamically create reactive forms in vue based on varying business o
1810

1911
Complete documentation and examples available at
2012

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

26-
## Install
16+
## Installation
2717

2818
```bash
2919
$ npm install @asigloo/vue-dynamic-forms
@@ -35,7 +25,11 @@ or if you prefer yarn
3525
$ yarn add @asigloo/vue-dynamic-forms
3626
```
3727

38-
Register the component
28+
## Usage
29+
30+
### Global
31+
32+
Register the component globally in your `main.js`:
3933

4034
```js
4135
import Vue from 'vue';
@@ -44,6 +38,220 @@ import VueDynamicForms from '@asigloo/vue-dynamic-forms';
4438
Vue.use(VueDynamicForms);
4539
```
4640

41+
### Local
42+
43+
You can include the dynamic form directly to your component.
44+
45+
```js
46+
import Vue from 'vue';
47+
import { DynamicForm } from '@asigloo/vue-dynamic-forms';
48+
49+
const components = { DynamicForm };
50+
51+
export {
52+
...
53+
components,
54+
...
55+
}
56+
```
57+
58+
### Form Composition
59+
60+
The dynamic form component is really easy to use, you will only need to add it to your template like this:
61+
62+
```html
63+
<template>
64+
<dynamic-form :id="testForm.id" :fields="testForm.fields" />
65+
<button type="submit" form="testForm.id">Submit</button>
66+
</template>
67+
```
68+
69+
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:
70+
71+
```js
72+
import { FormField } from '@asigloo/vue-dynamic-forms';
73+
74+
const yourAwesomeComponent = {
75+
name: 'your-awesome',
76+
data() {
77+
return {
78+
testForm: {
79+
id: 'test-form',
80+
fields: [
81+
new FormField({
82+
type: 'text',
83+
label: 'Name',
84+
name: 'name',
85+
}),
86+
new FormField({
87+
type: 'email',
88+
label: 'Email',
89+
name: 'email',
90+
}),
91+
],
92+
},
93+
};
94+
},
95+
};
96+
97+
export default yourAwesomeComponent;
98+
```
99+
100+
Each `FormField` has a set of properties to customize your input field:
101+
102+
| Property | Type | Default | Description |
103+
| :---------- | :--------------- | :------ | :----------------------------------------------------------------------------------------------------- |
104+
| type | String | text | Define the nature of the field, can be `text|email|url|password|number|radio|checkbox|textarea|select` |
105+
| label | String | null | Defines the text in the input label |
106+
| placeholder | String | null | Defines short hint that describes the expected value of an input field |
107+
| name | String | null | Name property for the field inside of the form data |
108+
| value | any | null | Initial value of the input field |
109+
| disabled | Boolean | false | Whenever the input field is disabled or not |
110+
| customClass | String | null | Allows the user to set custom classes to the input for styling purpouses |
111+
| options | Array of Objects | [] | Options for input type `select` |
112+
| inline | Boolean | false | Specifies if options for `radio|checkbox` should be inline |
113+
| validations | Array of Objects | [] | Array of `FormValidation` objects, specify validations and messages for the input |
114+
115+
### Events and Submit
116+
117+
| Event | Type | Emitter | Description |
118+
| :----------- | :--- | :------------ | :----------------------------------------------------------------------------------------------------------------------------- |
119+
| `submit` | | `DynamicForm` | Emits whenever the submit button has been clicked and the form is valid (no errors), returns all the form values in an Object |
120+
| `form-error` | | `DynamicForm` | Emits whenever the submit button has been clicked and the form is invalid (with errors), returns all errors |
121+
| `change` | | `DynamicForm` | Emits every time there is a value changed on the form, returns all the form values in an Object without the need ob submitting |
122+
123+
A small example of a form without submit button
124+
125+
```html
126+
<template>
127+
<dynamic-form
128+
:id="testForm.id"
129+
:fields="testForm.fields"
130+
@change="valuesChanged"
131+
/>
132+
</template>
133+
```
134+
135+
```js
136+
...
137+
const yourAwesomeComponent = {
138+
name: 'your-awesome',
139+
methods: {
140+
valuesChanged(values) {
141+
this.formData = {
142+
...this.formData,
143+
...values,
144+
};
145+
},
146+
}
147+
}
148+
...
149+
```
150+
151+
### Select input
152+
153+
```js
154+
...
155+
new FormField({
156+
type: 'select',
157+
label: 'Category',
158+
name: 'category',
159+
options: [
160+
{ value: null, text: 'Please select an option' },
161+
{ value: 'arduino', text: 'Arduino' },
162+
{ value: 'transistors', text: 'Transistors' },
163+
],
164+
}),
165+
...
166+
```
167+
168+
### Radio and Checkboxes
169+
170+
```js
171+
...
172+
new FormField({
173+
type: 'checkbox',
174+
label: 'Read the conditions',
175+
name: 'conditions',
176+
inline: false,
177+
}),
178+
new FormField({
179+
type: 'radio',
180+
label: 'Prefered Animal',
181+
name: 'animal',
182+
inline: true,
183+
options: [
184+
{ text: 'Dogs', value: 'dogs' },
185+
{ text: 'Cats', value: 'cats' },
186+
{ text: 'Others', value: 'others' },
187+
],
188+
}),
189+
...
190+
```
191+
192+
### Validation
193+
194+
This library offers a simple validation system using the property `validations` as an array of `FormValidation`objects containing the validation function and the text in case of error.
195+
196+
To use it you need the following code:
197+
198+
```js
199+
import {
200+
FormField,
201+
FormValidation,
202+
required,
203+
email,
204+
pattern,
205+
} from '@asigloo/vue-dynamic-forms';
206+
207+
const yourAwesomeComponent = {
208+
name: 'your-awesome',
209+
data() {
210+
return {
211+
testForm: {
212+
id: 'test-form',
213+
fields: [
214+
new FormField({
215+
type: 'text',
216+
label: 'Name',
217+
name: 'name',
218+
}),
219+
new FormField({
220+
type: 'email',
221+
label: 'Email',
222+
name: 'email',
223+
validations: [
224+
new FormValidation(required, 'This field is required'),
225+
new FormValidation(email, 'Format of email is incorrect'),
226+
],
227+
}),
228+
new FormField({
229+
type: 'password',
230+
label: 'Password',
231+
name: 'password',
232+
validations: [
233+
new FormValidation(required, 'This field is required'),
234+
new FormValidation(
235+
pattern(
236+
'^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[#$^+=!*()@%&]).{8,10}$',
237+
),
238+
'Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10',
239+
),
240+
],
241+
}),
242+
],
243+
},
244+
};
245+
},
246+
};
247+
248+
export default yourAwesomeComponent;
249+
```
250+
251+
### Styling themes
252+
253+
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 in `src/styles/themes/`
254+
47255
## Development
48256

49257
### Project setup
@@ -81,3 +289,22 @@ yarn run lint
81289
```
82290
yarn run test:unit
83291
```
292+
293+
## Contributing
294+
295+
If you find this library useful and you want to help improve it, maintain it or just want a new feature, feel free to contact me, or feel free to do a PR 😁.
296+
297+
## Todolist
298+
299+
This are the features I have planned for next versions of this library
300+
301+
- [ ] Material theme
302+
- [ ] Form Mixins for fields manipulation (for example, change values of a field depending of other)
303+
- [ ] More complex input types.
304+
- [ ] Nuxt plugin istall
305+
- [ ] Better docs & online examples
306+
- [ ] Storybook
307+
308+
## License
309+
310+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

0 commit comments

Comments
 (0)