Skip to content

Form-wide way to set error message on a field #209

@kettanaito

Description

@kettanaito

What

I suggest to expose a setError() method to set the error message to the provided field.

Why

Right now there is no way to set an error message to the specific field outside of the validation schema. Form asynchronous validation may often require to patch error messages to specific fields.

How

endUsageMethod() {
  this.formRef.setError('fieldName', 'Error message here');
}

Alternatively:

endUsageMethod() {
  this.formRef.setError({
    fieldName: 'Error message here',
    groupName: {
      fieldName: 'Another error message'
    }
  });
}

Specification

  • Support to set error message on the desired field
  • Support to set error messages on multiple fields at once

API

// single field
this.formRef.setError(['fieldName'], 'Error message')

// single grouped field
this.formRef.setError(['groupName', 'fieldName'], 'Error message')

// multiple fields
this.formRef.setError({
  fieldOne: 'Message one',
  fieldTwo: 'Message two'
})

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions