Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form 自动滚动到出错项 #993

Closed
yiminghe opened this issue Feb 3, 2016 · 4 comments
Closed

form 自动滚动到出错项 #993

yiminghe opened this issue Feb 3, 2016 · 4 comments
Assignees

Comments

@yiminghe
Copy link
Contributor

yiminghe commented Feb 3, 2016

http://react-component.github.io/form/examples/overview.html

function addScrollToValidate(validateFields) {
  return (...args) => {
    const originalCallback = args[args.length - 1];

    function newCb(error, values) {
      if (error) {
        for (const name in error) {
          if (error.hasOwnProperty(name) && error[name].instance) {
            scrollIntoView(ReactDOM.findDOMNode(error[name].instance), window, {
              onlyScrollIfNeeded: true,
            });
            break;
          }
        }
      }
      if (typeof originalCallback === 'function') {
        originalCallback(error, values);
      }
    }

    if (typeof originalCallback === 'function') {
      args[args.length - 1] = newCb;
    } else {
      args.push(newCb);
    }
    validateFields.apply(null, args);
  };
}

@createForm({
  refComponent: true,
  mapProps(props) {
    if (!this.__scrollAndValidate) {
      this.__scrollAndValidate = addScrollToValidate(props.form.validateFields);
    }
    return {
      ...props,
      scrollAndValidate: this.__scrollAndValidate,
    };
  },

滚动到 submit 点击,自动滚动到 user 处, 封装 validateFields

@benjycui
Copy link
Contributor

benjycui commented Feb 4, 2016

这个发到 1.0.0? @yiminghe @afc163

@yiminghe
Copy link
Contributor Author

yiminghe commented Feb 4, 2016

改动比较小,下个版本吧

@benjycui
Copy link
Contributor

benjycui commented Feb 4, 2016

0.12.2?

@lock
Copy link

lock bot commented May 6, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants