3. Basic usage

If you read the documentation of the final-form libary you will know that you will need the Field Component to render form elements. This library simply extends Field by adding JaRB validation rules to it. This abstraction is called JarbField. JarbField wraps final-form’s Field, and adds the auto validation from the JaRB constraints. In fact it is a very thin wrapper around Field. It only demands one extra property called ‘jarb’ which is used to to configure the Field. The jarb object needs two keys: the validator and the label.

For example:

<JarbField 
  name="Name" 
  jarb={{ validator: 'SuperHero.name', label: "Name" }}
  component="input" 
  type="text"
/>

The validator follows the following format: {Entity}.{Property}. For example if the validator property is SuperHero.name this means that the Field will apply the constraints for the ‘name’ property of the SuperHero entity. The label is used to inform you which field was wrong, when errors occur. You will receive the label when an error occurs to create a nice error message.