zerod 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Zform/index.jsx +44 -2
- package/package.json +1 -1
@@ -1,4 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
+
import ReactDOM from 'react-dom';
|
2
3
|
import { Form, Modal, Input, Button, Row, Col, message, ConfigProvider } from 'antd';
|
3
4
|
import zh_CN from 'antd/lib/locale-provider/zh_CN';
|
4
5
|
import PropTypes from 'prop-types';
|
@@ -245,7 +246,30 @@ export const Zform = Form.create()(
|
|
245
246
|
return newValue;
|
246
247
|
}
|
247
248
|
},
|
249
|
+
setErrorsId(rootEl, valuesIdMap) {
|
250
|
+
setTimeout(() => {
|
251
|
+
let root = rootEl || this.currRootEl;
|
252
|
+
|
253
|
+
if (root) {
|
254
|
+
if (root.localName === 'td') {
|
255
|
+
root = root.parentElement;
|
256
|
+
}
|
257
|
+
// console.dir(root);
|
258
|
+
Object.keys(valuesIdMap).forEach((key) => {
|
259
|
+
const inputEl = root.querySelector(`#${key}`);
|
260
|
+
let parEl = inputEl.parentElement;
|
261
|
+
while (parEl && !(parEl.className || '').includes('ant-form-item-control')) {
|
262
|
+
parEl = parEl.parentElement;
|
263
|
+
}
|
264
|
+
if (parEl) {
|
265
|
+
parEl.querySelector('.ant-form-explain').id = valuesIdMap[key];
|
266
|
+
}
|
267
|
+
});
|
268
|
+
}
|
269
|
+
}, 100);
|
270
|
+
},
|
248
271
|
setFieldsValue: (vals) => {
|
272
|
+
this.valuesIdMap = {};
|
249
273
|
const values = vals || this.props.values || this.props.formDefaultValues;
|
250
274
|
if (values) {
|
251
275
|
const saveSettingValues = { ...(this.state.saveSettingValues || {}), ...(values || {}) };
|
@@ -256,6 +280,7 @@ export const Zform = Form.create()(
|
|
256
280
|
const forms = !this.props.onlySetCurrentValues ? this.methods.getForms() : [this.form];
|
257
281
|
const otherFormItems = (this.props.getOtherFormItems && this.props.getOtherFormItems()) || [];
|
258
282
|
forms.forEach((form) => {
|
283
|
+
const valuesIdMap = {};
|
259
284
|
const formItems = form.zformItems.concat(otherFormItems);
|
260
285
|
if (values && formItems.length) {
|
261
286
|
const newValues = {};
|
@@ -268,6 +293,7 @@ export const Zform = Form.create()(
|
|
268
293
|
value: this.methods.treatValue({ key, value: value.value, formItems }),
|
269
294
|
errors: value.errors.map((item) => new Error(item)),
|
270
295
|
};
|
296
|
+
valuesIdMap[key] = value.valueId;
|
271
297
|
} else if (value !== undefined) {
|
272
298
|
newValues[key] = this.methods.treatValue({ key, value, formItems });
|
273
299
|
}
|
@@ -279,6 +305,7 @@ export const Zform = Form.create()(
|
|
279
305
|
if (Object.keys(newFields).length) {
|
280
306
|
form.setFields(newFields);
|
281
307
|
}
|
308
|
+
this.methods.setErrorsId(form.zform.currRootEl, valuesIdMap);
|
282
309
|
}
|
283
310
|
});
|
284
311
|
},
|
@@ -555,6 +582,7 @@ export const Zform = Form.create()(
|
|
555
582
|
saveOptionsMapKey: this.form.saveOptionsMapKey,
|
556
583
|
getAsyncQueue: () => this.allAsync,
|
557
584
|
saveSettingValues: this.state.saveSettingValues || {},
|
585
|
+
zform: this,
|
558
586
|
};
|
559
587
|
this.prevSettingValues = this.state.saveSettingValues;
|
560
588
|
this.prevPropsForm = this.props.form;
|
@@ -599,7 +627,13 @@ export const Zform = Form.create()(
|
|
599
627
|
const items = this.getFormItems();
|
600
628
|
const wrapperClassname = classNames('z-form', className || '');
|
601
629
|
return this.setAntdConfigProvider(
|
602
|
-
<Form
|
630
|
+
<Form
|
631
|
+
ref={(el) => {
|
632
|
+
this.currRootEl = ReactDOM.findDOMNode(el);
|
633
|
+
}}
|
634
|
+
onSubmit={this.methods.onSubmit}
|
635
|
+
className={wrapperClassname}
|
636
|
+
style={style}>
|
603
637
|
<Row type="flex" className={`z-form-row z-form-label-${labelLayout} z-form-control-${controlSize}`}>
|
604
638
|
{items}
|
605
639
|
</Row>
|
@@ -618,7 +652,15 @@ export const Zform = Form.create()(
|
|
618
652
|
);
|
619
653
|
}
|
620
654
|
setAntdConfigProvider(children) {
|
621
|
-
return
|
655
|
+
return (
|
656
|
+
<ConfigProvider
|
657
|
+
ref={(el) => {
|
658
|
+
this.currRootEl = ReactDOM.findDOMNode(el);
|
659
|
+
}}
|
660
|
+
locale={zh_CN}>
|
661
|
+
{children}
|
662
|
+
</ConfigProvider>
|
663
|
+
);
|
622
664
|
}
|
623
665
|
},
|
624
666
|
);
|