diff --git a/README.md b/README.md index 47c4f36d..f7ebadec 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Set fields by kv object. each field can contain errors and value member. Validate and get fields value by fieldNames. options is the same as validate method of [async-validator](https://github.com/yiminghe/async-validator). -add a new force member. +And add `force` and `scroll`. `scroll` is the same as [dom-scroll-into-view's function parameter `config`](https://github.com/yiminghe/dom-scroll-into-view#function-parameter). #### options.force: Boolean diff --git a/examples/overview.js b/examples/overview.js index 3d3ffb98..fc2a5b6b 100644 --- a/examples/overview.js +++ b/examples/overview.js @@ -188,7 +188,7 @@ class Form extends Component { onSubmit = (e) => { console.log('submit'); e.preventDefault(); - this.props.form.validateFieldsAndScroll((error, values) => { + this.props.form.validateFieldsAndScroll({ scroll: { offsetTop: 20 } }, (error, values) => { if (!error) { console.log('ok', values); } else { diff --git a/src/createDOMForm.jsx b/src/createDOMForm.jsx index 8dd2523e..c2f0075f 100644 --- a/src/createDOMForm.jsx +++ b/src/createDOMForm.jsx @@ -73,6 +73,7 @@ const mixin = { const c = options.container || getScrollableContainer(firstNode); scrollIntoView(firstNode, c, { onlyScrollIfNeeded: true, + ...options.scroll, }); } }