Skip to content

Commit 4268b0e

Browse files
committed
Merge branch 'hotfix/1.2.0'
2 parents a98c2da + 033abb3 commit 4268b0e

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

dist/index.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* element-form-builder v1.1.0
2+
* element-form-builder v1.2.0
33
* (c) 2019 Felix Yang
44
*/
55
var _extends = Object.assign || function (target) {
@@ -126,6 +126,22 @@ var FormBuilder = {
126126

127127
return _extends({}, defaultValues, model);
128128
},
129+
filterAttrs: function filterAttrs() {
130+
var detail = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
131+
132+
var keys = Object.keys(detail);
133+
var attrs = {};
134+
135+
keys.forEach(function (key) {
136+
var value = detail[key];
137+
138+
if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean') {
139+
attrs[key] = value;
140+
}
141+
});
142+
143+
return attrs;
144+
},
129145
renderFormItem: function renderFormItem(h, _ref2) {
130146
var tag = _ref2.tag,
131147
_ref2$item = _ref2.item,
@@ -149,14 +165,14 @@ var FormBuilder = {
149165

150166
if (tag === 'el-select') {
151167
var select = h(tag, {
152-
attrs: _extends({}, detail),
168+
attrs: _extends({}, vm.filterAttrs(detail)),
153169
props: _extends({
154170
value: value
155171
}, detail),
156172
on: _extends({}, modelEvents)
157173
}, (detail.items || []).map(function (option) {
158174
return h('el-option', {
159-
attrs: _extends({}, option),
175+
attrs: _extends({}, vm.filterAttrs(option)),
160176
props: _extends({
161177
key: option.value
162178
}, option)
@@ -165,14 +181,14 @@ var FormBuilder = {
165181
children = [select];
166182
} else if (tag === 'el-checkbox') {
167183
var checkbox = h('el-checkbox-group', {
168-
attrs: _extends({}, detail),
184+
attrs: _extends({}, vm.filterAttrs(detail)),
169185
props: _extends({
170186
value: value
171187
}, detail),
172188
on: _extends({}, modelEvents)
173189
}, (detail.items || []).map(function (option) {
174190
return h('el-checkbox', {
175-
attrs: _extends({}, option),
191+
attrs: _extends({}, vm.filterAttrs(option)),
176192
props: _extends({
177193
key: option.value,
178194
label: option.value
@@ -187,7 +203,7 @@ var FormBuilder = {
187203
name: detail.name
188204
}, option);
189205
return h(tag, {
190-
attrs: _extends({}, option),
206+
attrs: _extends({}, vm.filterAttrs(option)),
191207
props: _extends({
192208
value: value
193209
}, option),
@@ -197,7 +213,7 @@ var FormBuilder = {
197213
children = [].concat(toConsumableArray(radios));
198214
} else {
199215
var input = h(tag || 'el-input', {
200-
attrs: _extends({}, detail),
216+
attrs: _extends({}, vm.filterAttrs(detail)),
201217
props: _extends({
202218
value: value
203219
}, detail),

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "element-form-builder",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Build element-ui forms with JSON schema.",
55
"main": "dist/index.js",
66
"files": [

src/formbuilder.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ export default {
100100
}
101101
},
102102

103+
filterAttrs (detail = {}) {
104+
const keys = Object.keys(detail)
105+
const attrs = {}
106+
107+
keys.forEach(key => {
108+
const value = detail[key]
109+
110+
if (
111+
typeof value === 'number' ||
112+
typeof value === 'string' ||
113+
typeof value === 'boolean'
114+
) {
115+
attrs[key] = value
116+
}
117+
})
118+
119+
return attrs
120+
},
121+
103122
renderFormItem (h, { tag, item: label = {}, detail = {} }) {
104123
const vm = this
105124
const { formValues, size } = vm
@@ -118,7 +137,7 @@ export default {
118137
tag,
119138
{
120139
attrs: {
121-
...detail
140+
...vm.filterAttrs(detail)
122141
},
123142
props: {
124143
value,
@@ -131,7 +150,7 @@ export default {
131150
(detail.items || []).map(option => {
132151
return h('el-option', {
133152
attrs: {
134-
...option
153+
...vm.filterAttrs(option)
135154
},
136155
props: {
137156
key: option.value,
@@ -146,7 +165,7 @@ export default {
146165
'el-checkbox-group',
147166
{
148167
attrs: {
149-
...detail
168+
...vm.filterAttrs(detail)
150169
},
151170
props: {
152171
value,
@@ -161,7 +180,7 @@ export default {
161180
'el-checkbox',
162181
{
163182
attrs: {
164-
...option
183+
...vm.filterAttrs(option)
165184
},
166185
props: {
167186
key: option.value,
@@ -185,7 +204,7 @@ export default {
185204
tag,
186205
{
187206
attrs: {
188-
...option
207+
...vm.filterAttrs(option)
189208
},
190209
props: {
191210
value,
@@ -202,7 +221,7 @@ export default {
202221
} else {
203222
const input = h(tag || 'el-input', {
204223
attrs: {
205-
...detail
224+
...vm.filterAttrs(detail)
206225
},
207226
props: {
208227
value,

0 commit comments

Comments
 (0)