Redux-form: v6 and Sync Errors

Created on 14 Jul 2016  路  3Comments  路  Source: redux-form/redux-form

In version 6, synchronous validation only recognizes an error that is of type string, see here. Because of this, the form can still be submitted because the valid property is still true, despite the errors being passed correctly to their components.

Could this be changed to error !== undefined so you could pass Error, or arrays of string instead of strictly string?

enhancement

Most helpful comment

I'm just about to give redux-form a try, and I know I'll want individual fields to be able to be invalid in several ways simultaneously. ("This username is too short _and_ uses an illegal character".) I don't want to encode the entire error in a single message, for various reasons (l10n, ux).

As @tylergoodman said, currently it seems a validation function must return an object mapping field names to error strings, and only strings count as errors. Ideally, for me, if a field name were absent that would indicate OK; any other value would indicate error. The value returned would be passed through as-is to the field's component for rendering however it wishes.

At the moment, looks like I'll have to JSON.stringify an object of validation errors for each field, and JSON.parse it in the field's component.

All 3 comments

I'm just about to give redux-form a try, and I know I'll want individual fields to be able to be invalid in several ways simultaneously. ("This username is too short _and_ uses an illegal character".) I don't want to encode the entire error in a single message, for various reasons (l10n, ux).

As @tylergoodman said, currently it seems a validation function must return an object mapping field names to error strings, and only strings count as errors. Ideally, for me, if a field name were absent that would indicate OK; any other value would indicate error. The value returned would be passed through as-is to the field's component for rendering however it wishes.

At the moment, looks like I'll have to JSON.stringify an object of validation errors for each field, and JSON.parse it in the field's component.

That code was changed a while ago. The current requirement is that the error is a truthy value.

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.

Was this page helpful?
0 / 5 - 0 ratings