Skip to content

Commit 6f71ff7

Browse files
committed
Add helper vfjsHelperFieldDynamicProperties
1 parent f378250 commit 6f71ff7

File tree

1 file changed

+24
-1
lines changed
  • src/vfjs-global-mixin/methods/vfjs-helpers

1 file changed

+24
-1
lines changed

src/vfjs-global-mixin/methods/vfjs-helpers/index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { set, cloneDeep } from 'lodash';
1+
import { set, cloneDeep, merge } from 'lodash';
22
import vfjsFieldComponent from '../../../vfjs-field-component';
33

44
const vfjsHelpers = {
@@ -257,6 +257,29 @@ const vfjsHelpers = {
257257

258258
return oldErrors.length === 0;
259259
},
260+
vfjsHelperFieldDynamicProperties({ dynamicOptions, ...field }) {
261+
if (!dynamicOptions) {
262+
return null;
263+
}
264+
265+
if (Array.isArray(dynamicOptions)) {
266+
return dynamicOptions.reduce((properties, { schema, model, ...dynamicProperties }) => {
267+
if (this.vfjsHelperSchemaHasErrors(schema, model)) {
268+
return merge(properties, dynamicProperties);
269+
}
270+
271+
return properties;
272+
});
273+
}
274+
275+
const { schema, model, ...dynamicProperties } = dynamicOptions;
276+
if (this.vfjsHelperSchemaHasErrors(schema, model)) {
277+
console.log('dynamicProperties', dynamicProperties);
278+
return dynamicProperties;
279+
}
280+
281+
return null;
282+
},
260283
getVfjsFieldsModels(fields, fieldModels = []) {
261284
return fields.reduce((models, { children = [], model }) => {
262285
if (model) {

0 commit comments

Comments
 (0)