Coder Social home page Coder Social logo

42bv / jarb-final-form Goto Github PK

View Code? Open in Web Editor NEW
3.0 12.0 0.0 2.56 MB

Validating forms through JaRB, with react-final-form.

Home Page: https://42bv.github.io/jarb-final-form/

License: Other

JavaScript 1.87% TypeScript 94.36% Shell 3.77%
react final-form react-final-form jarb entity database validation

jarb-final-form's Introduction

About

Build Status Codecov

JaRB JaRB aims to improve database usage in Java enterprise applications. With JaRB you can get the validation rules from the database into Java. With this project you can get those rules into your react-final-form powered forms as well.

Installation

npm install @42.nl/jarb-final-form --save

Documentation

See the documentation

jarb-final-form's People

Contributors

dependabot[bot] avatar jvhoven avatar mrhus avatar sanderbenschop avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jarb-final-form's Issues

Boolean validation considers false wrong.

The boolean required validation requires the boolean to be of value true.

This is strange in the following situation: lets say we have a dropdown which shows three options and their values:

  1. "Do you agree", undefined
  2. "Yes", true
  3. "No" false

When you have a required boolean we currently only consider the option "Yes" valid. This is strange because "No" is perfectly valid. The only invalid choose is "Do you agree".

Historically a boolean required was considered sort of a "agree" choice which the user had to answer true too. We must change this behavior.

One caveat is that for a checkbox we would not accept the undefined value as valid. This means that the user must set all checkboxes too false manually by default. But this way we support al usecases.

Crash when setting a Java collection type as validator in JarbCheckboxMultipleSelect

Background

I have a JarbCheckboxMultipleSelect which has the following props:

<JarbCheckboxMultipleSelect
  name="nestedObjects"
  label="Geneste Objecten"
  optionForValue={someValue => someValue.description}
  options={getPossibleValuesBasedOnOtherValues(form.getState().values)}
  jarb={{
    validator: 'TheEntity.nestedObjects',
    label: 'Geneste objecten'
  }}
/>

The Java class for the root-level entity looks as following:

package nl._42.customer.project.the.package.to;

import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import nl._42.customer.project.the.package.to.TheNestedEntity;

/**
 * A class to demonstrate the issue with Jarb
 */
@Entity
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@ToString(callSuper = true)
public class TheEntity extends EntityWithCode {

    private UUID someRelatedId;

    private String description;

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "the_entity_id", updatable = false, nullable = false)
    private List<TheNestedEntity> nestedObjects;
}

This results in the /constraints endpoint giving the following response for the field nestedObjects:

"nestedObjects": {
   "javaType":"nl._42.customer.project.the.package.to.TheEntity",
   "required":false,
   "maximumLength":2147483647,
   "fractionLength":0,
   "radix":10,
   "name":"nestedObjects"
}

Expected behaviour

I expect that it is indicated whether or not it is required to pick at least one of the values using the checkboxes

Actual behaviour

The following error is logged and the application stops working:

utils.js:35 Uncaught TypeError: Cannot read property 'length' of undefined
    at Object.mostSpecificInputTypeFor (utils.js:35)
    at JarbField.getEnhancedValidate (JarbField.js:91)
    at JarbField.render (JarbField.js:184)
    at finishClassComponent (react-dom.development.js:17485)
    at updateClassComponent (react-dom.development.js:17435)
    at beginWork (react-dom.development.js:19073)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at beginWork$1 (react-dom.development.js:23964)
    at performUnitOfWork (react-dom.development.js:22776)
    at workLoopSync (react-dom.development.js:22707)
    at renderRootSync (react-dom.development.js:22670)
    at performSyncWorkOnRoot (react-dom.development.js:22293)
    at react-dom.development.js:11327
    at unstable_runWithPriority (scheduler.development.js:646)
    at runWithPriority$1 (react-dom.development.js:11276)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322)
    at flushSyncCallbackQueue (react-dom.development.js:11309)
    at discreteUpdates$1 (react-dom.development.js:22420)
    at discreteUpdates (react-dom.development.js:3756)
    at dispatchDiscreteEvent (react-dom.development.js:5889)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.