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

How to show validation errors for FieldArray on change of child attribute (v6.0.0-alpha7) #931

Closed
tacomanator opened this issue May 9, 2016 · 5 comments
Labels
Milestone

Comments

@tacomanator
Copy link

I'm trying out v6.0.0-alpha7 and having an issue in which a validation error set on the FieldArray is not showing when checking/unchecking the child field. Validation runs and sets the error, but the FieldArray component is not re-rendered.

Please excuse the syntax (LiveScript):

class Form extends Component

  render: ->
    element FieldArray,
      name: "children"
      component: (children) ->
        div null,

           # log statement only called on first render and when adding new children
           # it's not called when checking Field inside, even though that may clear or result in error
           console.log children.error

           choices.map (child) ->
            element Field,
              name: "#{child}.selected",
              component: "input",
              type: "checkbox"

          element Button,
            on-click: ~> children.push {selected: false}
            "Add child"

form-options =

  form: \group

  validate: ({children}) ->

    selected-count = sum map (.selected), children

    children: 
      if selected-count < 1
      then {_error: "Please select a child"}


module.exports = redux-form form-options <| Form

The log statement only fires at the beginning or when a new child is pushed into the FieldArray. It's not logging anything when checking/unchecking the checkbox.

Is this the intended behavior? Do I have to manually touch the FieldArray field when one of the children is changed?

@erikras
Copy link
Member

erikras commented May 9, 2016

This is a bug. There's a shouldComponentUpdate on FieldArray that is only updating if the length changes, and it needs to be looking at the sync errors, too. Thanks!

Man, that's some crazy-looking code. 🙈 👀 😆

@erikras erikras added the bug label May 9, 2016
@erikras erikras added this to the next-6.0.0 milestone May 9, 2016
@tacomanator
Copy link
Author

Ok, thank you ✌️

@halayli
Copy link

halayli commented May 11, 2016

http://redux-form.com/6.0.0-alpha.7/examples/fieldArrays/

If you just set the club name and hit submit the error 'At least one member must be entered' doesn't show up. I am guessing it's for the same reason?

@erikras
Copy link
Member

erikras commented May 12, 2016

Published fix as v6.0.0-alpha.9.

@erikras erikras closed this as completed May 12, 2016
@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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

No branches or pull requests

3 participants