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

Feature request: Provide option to customise ErrorList HTML like ArrayFieldTemplate #488

Closed
elisechant opened this issue Feb 25, 2017 · 7 comments

Comments

@elisechant
Copy link
Contributor

Description

It would be good to be able to write custom HTML for ErrorList at src/components/ErrorList.js in the same way we can for ArrayFieldTemplate.

@elisechant elisechant changed the title Feature request: Provide option to customise ErrorList like like ArrayFieldTemplate Feature request: Provide option to customise ErrorList like ArrayFieldTemplate Feb 25, 2017
@elisechant elisechant changed the title Feature request: Provide option to customise ErrorList like ArrayFieldTemplate Feature request: Provide option to customise ErrorList HTML like ArrayFieldTemplate Feb 25, 2017
@n1k0
Copy link
Collaborator

n1k0 commented Feb 28, 2017

That would be a great feature to have indeed. Anybody willing to work on that?

@revolunet
Copy link
Contributor

I also had to workaround that by creating a FieldTemplate with a custom ErrorList

would a ErrorList component props to the form do the trick ?

@n1k0
Copy link
Collaborator

n1k0 commented Feb 28, 2017

I think we're talking about the general ErrorList, the one rendered at the top of the form, not the contextual field errors one, for which a field template works nicely. But yeah, having the ability to customize the top one would be good, and passing a custom ErrorList component as a form prop would probably work best.

@n1k0
Copy link
Collaborator

n1k0 commented Mar 1, 2017

Yeah that's way too complicated, we should provide a simpler way. Who's willing to work on a PR? :)

@revolunet
Copy link
Contributor

unless @elisechant wants to give a shot, i can try the form prop solution

@elisechant
Copy link
Contributor Author

elisechant commented Mar 1, 2017

2 issues:

  1. no way to produce form level errors
  2. no way to trigger error based on an invalid server response

current workaround is to add global errors outside of form state, getting access to internal state by using a callback ref like <Form ref={(el) => this.form = el}:

class MyForm extends PureComponent {

  onSubmit({formData}) {
    return this.props.handleSubmit(formData).then((response) => {
      // success
    }).catch(error => {
      self.setState({
        globalErrors: [error && error.message ? error.message : 'Submit failed']
      });
      // can access internal form state from ref
      self.form.setState({status: "initial", errors: [], errorSchema: {}});
      return false;
    });
  }

  renderGlobalErrors() {
    const {globalErrors} = this.state;
    if (globalErrors && globalErrors.length) {
      return <div className="panel panel-danger errors">
        <ul className="list-group">{
          globalErrors.map((error, i) => {
            return (
              <li key={i} className="list-group-item text-danger">{
                error
              }</li>
            );
          })
        }</ul>
      </div>
    }
    return null;
  }

  render() {
    const {formData, schema, uiSchema} = this.state;

    return (
      <div>
        {this.renderGlobalErrors()}
        <Form ref={(el) => this.form = el} noHtml5Validate={true}
              autocomplete="off"
              formData={formData}
              schema={schema}
              uiSchema={uiSchema}
              onSubmit={this.onSubmit.bind(this)}/>
      </div>
    )
  }
}

Ideally the library might export some methods that could be used in place of indirect updates to internal form state or provide an optional wrapper component that does a global error state. Hard coding works for me for now but its not ideal.

revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
@revolunet revolunet mentioned this issue Mar 10, 2017
9 tasks
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 10, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 11, 2017
revolunet pushed a commit to revolunet/react-jsonschema-form that referenced this issue Mar 11, 2017
@n1k0 n1k0 closed this as completed in 7279ea9 Mar 12, 2017
n1k0 added a commit that referenced this issue Mar 21, 2017
New features

* Add support for rows attribute of textarea widget. (#450)
* #434 - Render empty array item fields when minItems is specified (#484)
* Add a "has-danger" class to the form error list (#502)
* Show description for boolean fields (#498)
* Fix #488: Add a custom Form ErrorList prop.

Bugfixes

* Fix impossibility to use stateful ArrayFieldTeplate comp. (#519)
* Centralized shouldComponentUpdate handling in SchemaField (#490)
@n1k0
Copy link
Collaborator

n1k0 commented Mar 21, 2017

Released in v0.44.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants