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

Commit a30f11b

Browse files
committed
Merge branch 'master' into feature/material-theme
2 parents 9ac52df + 71b6a9c commit a30f11b

File tree

14 files changed

+140
-20
lines changed

14 files changed

+140
-20
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ babel.config.js
77
vue.config.js
88
postcss.config.js
99
.prettierrc
10+
.git
11+
**/.git/
1012
yarn.lock
1113
/dev
1214
/docs

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"singleQuote": true,
33
"semi": true,
44
"trailingComma": "all",
5-
"disableLanguages": ["markdown"]
5+
"disableLanguages": ["markdown"],
6+
"arrowParens": "avoid"
67
}

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## 0.1.2 - 2020-05-05
9+
10+
### Fixed
11+
12+
- Added .git exclude to .npmignore to avoid EISGIT error ([#10](https://github.com/alvarosaburido/vue-dynamic-forms/issues/10))
13+
14+
## 0.1.1 - 2020-05-04
15+
16+
### Fixed
17+
18+
- Convert numeric values when updating form values ([#1](https://github.com/alvarosaburido/vue-dynamic-forms/issues/1))
19+
- Preselect option on Input-Select not working ([#7](https://github.com/alvarosaburido/vue-dynamic-forms/issues/7))
20+
- Missing github link in npm ([#8](https://github.com/alvarosaburido/vue-dynamic-forms/issues/6))
21+
822
## 0.1.0 - 2020-22-03
923

1024
### Added

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
# Vue Dynamic Forms
44

5-
![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)
5+
<p align="center">
6+
<a href="https://www.npmjs.com/package/@asigloo/vue-dynamic-forms">
7+
<img src="https://badgen.net/npm/v/@asigloo/vue-dynamic-forms" alt="Current npm version">
8+
</a>
9+
<a href="https://bundlephobia.com/result?p=@asigloo/[email protected]">
10+
<img src="https://flat.badgen.net/bundlephobia/min/@asigloo/vue-dynamic-forms" alt="Minified size">
11+
</a>
12+
<a href="https://vuejs.org">
13+
<img src="https://flat.badgen.net/badge/vue.js/2.6.x/4fc08d?icon=github" alt="Vue.js version">
14+
</a>
15+
</p>
616

717
Implementing handcrafted forms can be:
818
1. Costly

dev/App.vue

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@
77
<dynamic-form
88
:id="testForm.id"
99
:fields="testForm.fields"
10+
:customClass="'row'"
1011
@change="valuesChanged"
11-
/>
12+
>
13+
<template slot="custom-field-1" slot-scope="props">
14+
<div class="pika-field">
15+
<input
16+
v-if="props.field"
17+
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()"
24+
/>
25+
<img src="./assets/pika.png" alt="" />
26+
</div>
27+
</template>
28+
</dynamic-form>
1229
<div class="row d-flex justify-content-end p-4">
1330
<button submit="true" :form="testForm.id" class="btn btn-primary">
1431
Submit
@@ -43,11 +60,13 @@ const data = () => ({
4360
type: 'text',
4461
label: 'Name',
4562
name: 'name',
63+
customClass: 'col-12',
4664
}),
4765
new FormField({
4866
type: 'email',
4967
label: 'Email',
5068
name: 'email',
69+
customClass: 'col-12',
5170
validations: [
5271
new FormValidation(required, 'This field is required'),
5372
new FormValidation(email, 'Format of email is incorrect'),
@@ -57,6 +76,7 @@ const data = () => ({
5776
type: 'password',
5877
label: 'Password',
5978
name: 'password',
79+
customClass: 'col-12',
6080
validations: [
6181
new FormValidation(required, 'This field is required'),
6282
new FormValidation(
@@ -75,42 +95,58 @@ const data = () => ({
7595
name: 'bio',
7696
cols: 30,
7797
rows: 5,
98+
customClass: 'col-12',
7899
}),
79100
new FormField({
80101
type: 'select',
81102
label: 'Category',
82103
name: 'category',
83-
value: 'arduino',
104+
customClass: 'col-12',
84105
options: [
85106
{ value: null, text: 'Please select an option' },
86-
{ value: 'actionfield', text: 'Action field' },
87-
{ value: 'advancedselect', text: 'Advanced select' },
88-
{ value: 'autocomplete', text: 'Autocomplete' },
89-
{ value: 'buttongroup', text: 'Button group' },
107+
{ value: 'arduino', text: 'Arduino' },
108+
{ value: 'transistors', text: 'Transistors' },
109+
{ value: 'resistors', text: 'Resistors', disabled: true },
90110
],
91111
}),
92112
new FormField({
93113
type: 'checkbox',
94114
label: 'Read the conditions',
95115
name: 'conditions',
96116
inline: false,
117+
customClass: 'col-12',
97118
}),
98119
new FormField({
99120
type: 'radio',
100121
label: 'Prefered Animal',
101122
name: 'animal',
102123
inline: true,
124+
customClass: 'col-12',
103125
options: [
104126
{ text: 'Dogs', value: 'dogs' },
105127
{ text: 'Cats', value: 'cats' },
106128
{ text: 'Others', value: 'others' },
107129
],
108130
}),
131+
new FormField({
132+
type: 'custom-field',
133+
label: 'Custom Field 1',
134+
name: 'custom-field-1',
135+
customClass: 'col-12',
136+
}),
109137
new FormField({
110138
type: 'number',
111139
label: 'Number',
112140
name: 'number',
113141
value: 0,
142+
customClass: 'col-12 col-md-6',
143+
}),
144+
new FormField({
145+
type: 'number',
146+
label: 'Number 2',
147+
name: 'number2',
148+
value: 50,
149+
customClass: 'col-12 col-md-6',
114150
}),
115151
],
116152
},
@@ -132,3 +168,14 @@ export default {
132168
methods,
133169
};
134170
</script>
171+
<style lang="scss">
172+
.pika-field {
173+
position: relative;
174+
175+
img {
176+
position: absolute;
177+
top: 5px;
178+
right: 5px;
179+
}
180+
}
181+
</style>

dev/assets/pika.png

2.28 KB
Loading

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
22
"name": "@asigloo/vue-dynamic-forms",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"description": "Easy way to dynamically create reactive forms in vue based on varying business object model",
55
"author": "Alvaro Saburido <[email protected]>",
66
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/alvarosaburido/vue-dynamic-forms.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/alvarosaburido/vue-dynamic-forms/issues"
13+
},
714
"scripts": {
815
"serve": "vue-cli-service serve",
916
"build": "vue-cli-service build --target lib --name as-dynamic-forms src/main.js",

src/components/dynamic-form/DynamicForm.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const props = {
2121
default: 'POST',
2222
type: String,
2323
},
24-
classes: {
24+
customClass: {
2525
default: null,
2626
type: String,
2727
},
@@ -111,17 +111,27 @@ const computed = {
111111
}, {})
112112
: {};
113113
},
114+
deNormalizedScopedSlots() {
115+
return Object.keys(this.$scopedSlots);
116+
},
117+
normalizedControls() {
118+
let controls = {};
119+
this.controls.forEach(element => {
120+
controls[element.name] = element;
121+
});
122+
return controls;
123+
},
114124
};
115125

116126
const watch = {
117127
fields: {
118-
handler: function() {
128+
handler: function () {
119129
this.mapControls();
120130
},
121131
deep: true,
122132
},
123133
values: {
124-
handler: function() {
134+
handler: function () {
125135
this.$emit('change', this.values);
126136
},
127137
deep: true,

src/components/dynamic-form/DynamicForm.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v-if="fields.length > 0 && !showFeedback"
55
:id="id"
66
:name="id"
7-
:class="classes"
7+
:class="customClass"
88
:method="method"
99
novalidate
1010
@submit.prevent="handleSubmit()"
@@ -14,7 +14,20 @@
1414
v-for="field in controls"
1515
:key="field.name"
1616
:form-control="field"
17-
/>
17+
>
18+
<template slot="custom-field" slot-scope="props">
19+
<div v-for="slot in deNormalizedScopedSlots" :key="slot">
20+
<slot
21+
v-if="props.control.name === slot"
22+
:name="slot"
23+
:field="normalizedControls[slot]"
24+
:valueChange="props.valueChange"
25+
:onFocus="props.onFocus"
26+
:onBlur="props.onBlur"
27+
></slot>
28+
</div>
29+
</template>
30+
</dynamic-input>
1831
</form>
1932
<div v-if="showFeedback" class="dynamic-form__feedback">
2033
{{ feedbackText }}

0 commit comments

Comments
 (0)