{"id":18595829,"url":"https://github.com/42bv/jarb-redux-form","last_synced_at":"2026-05-07T19:12:39.538Z","repository":{"id":39459533,"uuid":"85930798","full_name":"42BV/jarb-redux-form","owner":"42BV","description":"Validating forms through JaRB, with redux-form.","archived":false,"fork":false,"pushed_at":"2023-01-03T15:16:02.000Z","size":1350,"stargazers_count":2,"open_issues_count":16,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-01-27T06:17:19.788Z","etag":null,"topics":["constraints","database","entity","jarb","react","redux-form","validation"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/42BV.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-23T09:25:54.000Z","updated_at":"2019-05-27T07:50:32.000Z","dependencies_parsed_at":"2023-02-01T07:01:04.833Z","dependency_job_id":null,"html_url":"https://github.com/42BV/jarb-redux-form","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42BV%2Fjarb-redux-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42BV%2Fjarb-redux-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42BV%2Fjarb-redux-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42BV%2Fjarb-redux-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/42BV","download_url":"https://codeload.github.com/42BV/jarb-redux-form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239379323,"owners_count":19628684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["constraints","database","entity","jarb","react","redux-form","validation"],"created_at":"2024-11-07T01:21:41.388Z","updated_at":"2025-10-30T14:40:21.726Z","avatar_url":"https://github.com/42BV.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\n[![Build Status](https://travis-ci.org/42BV/jarb-redux-form.svg?branch=master)](https://travis-ci.org/42BV/jarb-redux-form)\n[![Codecov](https://codecov.io/gh/42BV/jarb-redux-form/branch/master/graph/badge.svg)](https://codecov.io/gh/42BV/jarb-redux-form)\n\n[JaRB](http://www.jarbframework.org/) JaRB aims to improve database \nusage in Java enterprise applications. With JaRB you can get the\nvalidation rules from the database into Java. With this project\nyou can get those rules into your [redux-form](http://redux-form.com/) powered\nforms as well.\n\n# Installation\n\n`npm install jarb-redux-form --save`\n\n# Preparation\n\nFirst in your Java project make sure jarb-redux-form can read\nthe contraints, via a GET request:\n\n```Java\n// EntityConstraintsController.java\n\n@RestController\n@RequestMapping(\"/constraints\")\npublic class ConstraintsController {\n    private final BeanConstraintService beanConstraintService;\n\n    @Autowired\n    ConstraintsController(BeanConstraintDescriptor beanConstraintDescriptor) {\n        beanConstraintService = new BeanConstraintService(beanConstraintDescriptor);\n        beanConstraintService.registerAllWithAnnotation(Application.class, Entity.class);\n    }\n\n    @RequestMapping(method = RequestMethod.GET)\n    Map\u003cString, Map\u003cString, PropertyConstraintDescription\u003e\u003e describeAll() {\n        return beanConstraintService.describeAll();\n    }\n}\n```\n\n# Getting started.\n\nWe assume you have a working Redux project, if you do not yet have\nRedux add Redux to your project by following the Redux's instructions.\n\nWe also assume that you have redux-form installed via the instructions\nprovided on the website.\n\nFirst install the following dependencies in the package.json:\n\n  1. \"react-redux\": \"^6.0.0\",\n  2. \"redux\": \"3.6.0\",\n  3. \"redux-form\": \"^8.1.0\"\n\nNow add the constraints-reducer to your rootReducer for example:\n\n```js\nimport { combineReducers } from 'redux';\nimport { reducer as formReducer } from 'redux-form';\nimport { constraints, ConstraintsStore } from 'jarb-redux-form';\n\nexport type Store = {\n  constraints: ConstraintsStore\n};\n\n// Use ES6 object literal shorthand syntax to define the object shape\nconst rootReducer: Store = combineReducers({\n  constraints,\n  form: formReducer\n});\n\nexport default rootReducer;\n```\n\nThis should add the ConstraintsStore to Redux, which will store\nthe constraints from JaRB.\n\nNext you have to configure the constraints module:\n\n```js\nimport { createStore } from 'redux';\nimport { configureConstraint } from 'jarb-redux-form';\n\nexport const store = createStore(\n  rootReducer,\n);\n\nconfigureConstraint({\n   // The URL which will provide the constraints over a GET request.\n  constraintsUrl: '/api/constraints',\n\n  // Whether or not the 'constraintsUrl' should be called with authentication.\n  needsAuthentication: true,\n\n  // The dispatch function for the Redux store.\n  dispatch: store.dispatch,\n\n  // A function which returns the latests ConstraintsStore from Redux.\n  constraintsStore: () =\u003e store.getState().constraints\n});\n```\n\nThe constraints module must be configured before the application\nis rendered.\n\nFinally you will have load the constraints from the back-end using\nthe `loadConstraints` function. If in order for the constraints\nto be loaded you need to be logged in, you should load the constraints\nas soon as you know that you are logged in:\n\n```js\nimport { loadConstraints } from 'jarb-redux-form';\nimport { login } from 'somewhere';\n\nclass Login extends Component {\n  doLogin(username, password) {\n    login({ username, password })\n      .then(loadConstraints); // Load constraints ASAP\n  }\n\n  render() {\n    // Render here which calls doLogin\n  }\n}\n```\n\nIf you do not need a login before you can fetch the constraints\nsimply fetch them using `loadContraints` as soon as possible.\n\n# Usage\n\n## Using JarbField\n\nIf you read the documentation of the redux-form libary you will know\nthat you will need the `Field` Component to render form elements. This\nlibrary simply extends `Field` by adding JaRB validation rules to it.\n\nThis abstraction is called `JarbField`. JarbField wrappes \nredux-form's Field, and adds the auto validation from the \nConstraintsStore. In fact it is a very thin wrapper around\nField.\n\nIt only demands one extra property called 'jarb' which is used\nto to configure the Field. The 'jarb' object needs two keys:\nthe 'validator' and the 'label'. \n\nThe 'validator' follows the following format: {Entity}.{Property}. \nFor example if the validator property is 'SuperHero.name' this means that\nthe Field will apply the constraints for the 'name' property of\nthe 'SuperHero' entity.\n \nThe 'label' is used to inform you which field was wrong, when errors occur.\nYou will receive the 'label' when an error occurs to create a nice\nerror message.\n\nFor example:\n\n```js\n\u003cJarbField \n  name=\"Name\" \n  jarb={{ validator: 'SuperHero.name', label: \"Name\" }} \n  component=\"input\" \n  type=\"text\"\n/\u003e\n```\n\n## Displaying erors\n\nRendering the validation errors is completely up to you.\n\nThe way it works is as follows, whenever an error occurs\nthe `error` prop of the Field's `meta` data will contain\nan object with the following shape:\n\n```js\n{\n  // The type of error which occured\n  \"type\": \"ERROR_MINIMUM_LENGTH\",\n  // The label of the JarbField\n  \"label\": \"Description\",\n  // The value that the field possesed at the time of the error\n  \"value\": '',\n  // The reason why the error occured.\n  \"reasons\": { \"minimumLength\": 3 }\n}\n``` \n\nThe following `ValidationType`'s exist:\n\n```JavaScript\nexport type ValidationType = 'ERROR_REQUIRED'\n                           | 'ERROR_MINIMUM_LENGTH'\n                           | 'ERROR_MAXIMUM_LENGTH'\n                           | 'ERROR_MIN_VALUE'\n                           | 'ERROR_MAX_VALUE'\n                           | 'ERROR_PATTERN';\n```\n\nNow you could create an Error Component to render the errors:\n\n```js\nimport { ValidationError } from 'jarb-redux-form';\nimport React, { Component } from 'react';\n\ninterface Props {\n  meta: {\n    invalid: boolean,\n    error: ValidationError,\n    touched: boolean\n  }\n}\n\nexport default function Error(props: Props) {\n  render() {\n    const { invalid, error, touched } = props.meta;\n\n    if (invalid \u0026\u0026 touched) {\n      return \u003cspan className=\"error\"\u003e{ errorMessage(error) }\u003c/span\u003e;\n    }\n\n    return null;\n  }\n};\n\n// Render a nice message based on each ValidationType.\nfunction errorMessage(error: ValidationError): string {\n  switch(error.type) {\n    case 'ERROR_REQUIRED':\n      return `${ error.label } is required`;\n    case 'ERROR_MINIMUM_LENGTH':\n      return `${ error.label } must be bigger than ${ error.reasons.minimumLength } characters`;\n    case 'ERROR_MAXIMUM_LENGTH':\n      return `${ error.label } must be smaller than ${ error.reasons.maximumLength } characters`;\n    case 'ERROR_MIN_VALUE':\n      return `${ error.label } must be more than ${ error.reasons.minValue }`;\n    case 'ERROR_MAX_VALUE':\n      return `${ error.label } must be less than ${ error.reasons.maxValue }`;\n    case 'ERROR_PATTERN':\n      return `${ error.label } does not match the pattern: ${error.reasons.regex`;\n    default:\n     return 'UNKNOWN_ERROR';\n  }\n}\n```\n\nHere are examples of all errors which can occur:\n\n```js\n{\n  \"type\": \"ERROR_REQUIRED\",\n  \"label\": \"Name\",\n  \"value\": '',\n  \"reasons\": { \"required\": \"required\" }\n}\n\n{\n  \"type\": \"ERROR_MINIMUM_LENGTH\",\n  \"label\": \"Description\",\n  \"value\": '',\n  \"reasons\": { \"minimumLength\": 3 }\n}\n\n{\n  \"type\": \"ERROR_MAXIMUM_LENGTH\",\n  \"label\": \"Info\",\n  \"value\": 'aaaa',\n  \"reasons\": { \"maximumLength\": 3 }\n}\n\n{\n  \"type\": \"ERROR_MIN_VALUE\",\n  \"label\": \"Age\",\n  \"value\": 1,\n  \"reasons\": { \"minValue\": 15 }\n}\n\n{\n  \"type\": \"ERROR_MAX_VALUE\",\n  \"label\": \"Amount\",\n  \"value\": 16,\n  \"reasons\": { \"maxValue\": 15 }\n}\n\n{\n  \"type\": \"ERROR_PATTERN\",\n  \"label\": \"Telephone\",\n  \"value\": 'noot',\n  \"reasons\": { \"regex\": /^-?\\d+$/ }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F42bv%2Fjarb-redux-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F42bv%2Fjarb-redux-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F42bv%2Fjarb-redux-form/lists"}