Skip to content

Commit 64ccf13

Browse files
committed
[2.5.4] FieldArray now supports Component as renderField prop
1 parent 54c6723 commit 64ccf13

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
## 2.5.4
2+
3+
### Updated
4+
5+
- `renderField` now supports not only a function as prop value, also it supports any Component
6+
- A Component will get `{ data, fields, name }` options, where `data` is an Array, `fields` is an Object with methods to manipulate that Array, `name` is a String passed as a `name` to `ArrayField` component
7+
8+
```js
9+
import Form, { ArrayField } from '@detools/vue-form'
10+
import Tasklist from '@/components/Tasklist'
11+
12+
// OK
13+
const renderAsFunction = {
14+
render() {
15+
methods: {
16+
renderTasklist({ data, fields, name }) {
17+
return <Tasklist data={data} fields={fields} name={name} />
18+
},
19+
},
20+
21+
return (
22+
<Form>
23+
<ArrayField name="tasklist" renderField={this.renderTasklist} />
24+
</Form>
25+
)
26+
}
27+
}
28+
29+
// NOW OK
30+
const renderAsComponent = {
31+
render() {
32+
return (
33+
<Form>
34+
<ArrayField name="tasklist" renderField={Tasklist} />
35+
</Form>
36+
)
37+
}
38+
}
39+
```
40+
141
## 2.5.3
242

343
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ See demo at [https://detools.github.io/vue-form](https://detools.github.io/vue-f
7979

8080
## Changelog
8181

82+
- [2.5.4](/CHANGELOG.md#254)
8283
- [2.5.3](/CHANGELOG.md#253)
8384
- [2.5.2](/CHANGELOG.md#252)
8485
- [2.5.1](/CHANGELOG.md#251)

VueForm/components/ConnectedArrayField.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import without from 'lodash/without'
22
import last from 'lodash/last'
3+
import isFunction from 'lodash/isFunction'
34
import { ConnectedArrayFieldMixin } from '../mixins/ConnectedControl'
45

56
export default {
@@ -18,7 +19,7 @@ export default {
1819
asyncValidators: Array,
1920

2021
renderField: {
21-
type: Function,
22+
type: [Function, Object],
2223
required: true,
2324
},
2425
},
@@ -169,8 +170,14 @@ export default {
169170
return nextArray
170171
},
171172

172-
renderComponent(value) {
173-
return this.renderField({ data: value, fields: this.fields })
173+
renderComponent(value, setValue, createElement) {
174+
const props = { data: value, fields: this.fields, name: this.name }
175+
176+
if (isFunction(this.renderField)) {
177+
return this.renderField(props)
178+
}
179+
180+
return createElement(this.renderField, { props })
174181
},
175182
},
176183
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@detools/vue-form",
3-
"version": "2.5.3",
3+
"version": "2.5.4",
44
"description": "Form State Management for VueJS",
55
"main": "VueForm/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)