You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add legacy test
* sync logic with legacy validate
* update test case & doc
* support rule be a validator function directly
* throw if out of date
* add clean-field test
* fix prettier
* mainly test
* add dynamic-binding test
Copy file name to clipboardExpand all lines: README.md
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,3 +194,58 @@ Validate Messages provides a list of error template. You can ref [here](https://
194
194
| name | Field name |
195
195
| pattern | Rule `pattern` prop |
196
196
| type | Rule `type` prop |
197
+
198
+
# Different with `rc-form`
199
+
200
+
`rc-field-form` is try to keep sync with `rc-form` in api level, but there still have something to change:
201
+
202
+
## 🔥 Remove Field will not clean up related value
203
+
204
+
We do lots of logic to clean up the value when Field removed before. But with user feedback, remove exist value increase the additional work to keep value back with conditional field.
205
+
206
+
## 🔥 Nest name use array instead of string
207
+
208
+
In `rc-form`, we support like `user.name` to be a name and convert value to `{ user: { name: 'Bamboo' } }`. This makes '.' always be the route of variable, this makes developer have to do additional work if name is real contains a point like `app.config.start` to be `app_config_start` and parse back to point when submit.
209
+
210
+
Field Form will only trade `['user', 'name']` to be `{ user: { name: 'Bamboo' } }`, and `user.name` to be `{ ['user.name']: 'Bamboo' }`.
211
+
212
+
## 🔥 `getFieldsError` always return array
213
+
214
+
`rc-form` returns `null` when no error happen. This makes user have to do some additional code like:
Now `getFieldsError` will return `[]` if no errors.
223
+
224
+
## 🔥 Remove `callback` with `validateFields`
225
+
226
+
Since ES8 is support `async/await`, that's no reason not to use it. Now you can easily handle your validate logic:
227
+
228
+
```js
229
+
asyncfunction() {
230
+
try {
231
+
constvalues=awaitform.validateFields();
232
+
console.log(values);
233
+
} catch (errorList) {
234
+
errorList.forEach(({ name, errors }) => {
235
+
// Do something...
236
+
});
237
+
}
238
+
}
239
+
```
240
+
241
+
**Notice: Now if your validator return an `Error(message)`, not need to get error by `e => e.message`. FieldForm will handle this.**
242
+
243
+
## 🔥 `preserve` is no need anymore
244
+
245
+
In `rc-form` you should use `preserve` to keep a value cause Form will auto remove a value from Field removed. Field Form will always keep the value in the Form whatever Field removed.
246
+
247
+
## 🔥 `setFields` not trigger `onFieldsChange` and `setFieldsValue` not trigger `onValuesChange`
248
+
249
+
In `rc-form`, we hope to help user auto trigger change event by setting to make redux dispatch easier, but it's not good design since it makes code logic couping.
250
+
251
+
Additionally, user control update trigger `onFieldsChange` & `onValuesChange` event has potential dead loop risk.
0 commit comments