Browse Source

fix: onChange -> onValuesChange on Form to watch field changes

master
smallstonesk 5 years ago
parent
commit
f122e3f2c0
  1. 8
      packages/core/src/components/codeRun/inputPanel/index.tsx

8
packages/core/src/components/codeRun/inputPanel/index.tsx

@ -89,14 +89,14 @@ const VisualPanel: React.FC<IVisualPanelProps> = (props) => {
form.setFieldsValue(filedsValue); form.setFieldsValue(filedsValue);
}, [data]); }, [data]);
const onFormChange = () => { const onFormValuesChange = () => {
const input: { [key: string]: any } = {}; const input: { [key: string]: any } = {};
const filedsValue = form.getFieldsValue(); const filedsValue = form.getFieldsValue();
for (const { type } of inputItems) { for (const { type } of inputItems) {
const mockValue = filedsValue[type] || []; const mockValue = filedsValue[type] || [];
input[type] = mockValue.reduce( input[type] = mockValue.reduce(
(prev: any, cur: { key: string; value: any }) => { (prev: any, cur: { key: string; value: any }) => {
const { key, value } = cur; const { key = '', value } = cur || {};
prev[key] = value; prev[key] = value;
return prev; return prev;
}, },
@ -108,7 +108,7 @@ const VisualPanel: React.FC<IVisualPanelProps> = (props) => {
return ( return (
<div className={styles.visualInput}> <div className={styles.visualInput}>
<Form form={form} autoComplete={'on'} onChange={onFormChange}> <Form form={form} autoComplete={'on'} onValuesChange={onFormValuesChange}>
{inputItems.map(({ type, desc }, index) => ( {inputItems.map(({ type, desc }, index) => (
<VisualFormItem key={index} type={type} desc={desc} /> <VisualFormItem key={index} type={type} desc={desc} />
))} ))}
@ -136,7 +136,7 @@ const InputPanel: React.FC<IInputPanelProps> = (props) => {
try { try {
onChange(JSON.parse(newCode)); onChange(JSON.parse(newCode));
} catch (err) { } catch (err) {
console.log(err); // cancel log to avoid wasting Console outputs
} }
}, 1000); }, 1000);
}; };

Loading…
Cancel
Save