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

Commit 8cf29b8

Browse files
authored
Merge pull request #25 from alvarosaburido/feature/vue_press_docs
Feature/vue press docs
2 parents 7ef4cc9 + eb465e9 commit 8cf29b8

File tree

125 files changed

+4788
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+4788
-304
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.vuegenerator
33
.eslintrc.js
44
.eslintignore
5+
netlify.toml
56
jest.config.js
67
babel.config.js
78
vue.config.js

README.md

Lines changed: 6 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![repository-banner.png](https://res.cloudinary.com/alvarosaburido/image/upload/v1564929632/as-readme-banner_tqdgrx.png)
1+
![Library Banner](https://res.cloudinary.com/alvarosaburido/image/upload/v1589993773/portfolio/web/vue-dynamic-forms/open-graph-preview_kv4glm.png)
22

33
# Vue Dynamic Forms
44

@@ -15,20 +15,21 @@
1515
</p>
1616

1717
Implementing handcrafted forms can be:
18+
1819
1. Costly
1920
2. Time-consuming
2021

21-
Specially if you need to create a very large form, in which the inputs are similar to each other, and they change frequently to meet rapidly changing business and regulatory requirements.
22+
Especially if you need to create a very large form, in which the inputs are similar to each other, and they change frequently to meet rapidly changing business and regulatory requirements.
2223

23-
So, will not be more economical to create the forms dynamically? Based on metadata that describes the business object model?
24+
So, wouldn't it be more economical to create the forms dynamically? Based on metadata that describes the business object model?
2425

2526
That's Vue Dynamic Forms.
2627

2728
## Documentation
2829

2930
Complete documentation and examples available at
3031

31-
- **[API Documentation]()** (soon)
32+
- **[Documentation](https://vue-dynamic-forms.netlify.app)**
3233
- **[Sandbox Demo](https://codesandbox.io/s/vue-dynamic-forms-ftzes)**
3334

3435
## Installation
@@ -73,207 +74,6 @@ export {
7374
}
7475
```
7576

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

27979
### Project setup
@@ -324,7 +124,7 @@ This are the features I have planned for next versions of this library
324124
- [ ] Form Mixins for fields manipulation (for example, change values of a field depending of other)
325125
- [ ] More complex input types.
326126
- [ ] Nuxt plugin istall
327-
- [ ] Better docs & online examples
127+
- [x] Better docs & online examples
328128
- [ ] Storybook
329129

330130
## License

dev/App.vue

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@
1010
:options="testForm.options"
1111
@change="valuesChanged"
1212
>
13-
<template slot="custom-field-1" slot-scope="props">
14-
<div class="pika-field">
13+
<template
14+
slot="custom-field-1"
15+
slot-scope="{ control, valueChange, onFocus, onBlur }"
16+
>
17+
<div class="avocado-field">
1518
<input
16-
v-if="props.field"
19+
v-if="control"
1720
class="form-control"
18-
v-model="props.field.value"
19-
:type="props.field.type"
20-
:name="props.field.name"
21-
@change="props.valueChange()"
22-
@focus="props.onFocus()"
23-
@blur="props.onBlur()"
21+
v-model="control.value"
22+
:type="control.type"
23+
:name="control.name"
24+
@change="valueChange()"
25+
@focus="onFocus()"
26+
@blur="onBlur()"
2427
/>
25-
<img src="./assets/pika.png" alt="" />
28+
<i>🥑</i>
2629
</div>
2730
</template>
2831
</dynamic-form>
@@ -159,7 +162,7 @@ const data = () => ({
159162
}),
160163
],
161164
options: {
162-
// autoValidate: true,
165+
autoValidate: true,
163166
customClass: 'row',
164167
netlify: true,
165168
},
@@ -183,10 +186,16 @@ export default {
183186
};
184187
</script>
185188
<style lang="scss">
186-
.pika-field {
189+
.avocado-field {
187190
position: relative;
188191
189-
img {
192+
.form-control {
193+
border-color: #aec64c;
194+
background-color: #e2eb5d52;
195+
border-radius: 16px;
196+
}
197+
198+
i {
190199
position: absolute;
191200
top: 5px;
192201
right: 5px;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<ul class="features">
3+
<li v-for="feature in features" class="feature">
4+
<h3 class="title">{{ feature.title }}</h3>
5+
<p class="text">{{ feature.text }}</p>
6+
</li>
7+
</ul>
8+
</template>
9+
10+
<script>
11+
import features from '../data/features';
12+
13+
export default {
14+
name: 'Features',
15+
data: () => ({
16+
features,
17+
}),
18+
};
19+
</script>
20+
21+
<style lang="scss">
22+
.features {
23+
display: flex;
24+
list-style: none;
25+
margin: 0;
26+
padding: 0;
27+
margin-left: -15px;
28+
margin-right: -15px;
29+
justify-content: flex-start;
30+
flex-wrap: wrap;
31+
}
32+
.feature {
33+
padding: 15px;
34+
width: 45%;
35+
}
36+
</style>

0 commit comments

Comments
 (0)