ant-design/components/form/ValueMixin.tsx

23 lines
514 B
TypeScript
Raw Normal View History

2016-06-22 13:18:43 +08:00
import assign from 'object-assign';
2015-10-25 11:31:48 +08:00
const ValueMixin = {
setValue(field, e) {
let v = e;
const target = e && e.target;
if (target) {
if ((`${target.nodeName}`).toLowerCase() === 'input' &&
2015-10-25 11:31:48 +08:00
target.type === 'checkbox') {
v = target.checked;
} else {
v = e.target.value;
}
}
const newFormData = {};
newFormData[field] = v;
this.setState({
2016-06-22 13:18:43 +08:00
formData: assign({}, this.state.formData, newFormData),
2015-10-25 11:31:48 +08:00
});
},
};
export default ValueMixin;