Coder Social home page Coder Social logo

react-form-wrapper's People

Contributors

ikatun avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ikatun

react-form-wrapper's Issues

disableSubmit configuration function

NOTE: TEMPORARY, UNTIL VALIDATION API IMPLEMENTED

enable FormWrapper to accept a disableSubmit function, that runs on every update, receives the form values, and returns a boolean.

Documentation

Provide documentation for basic functionality and intended validation API.

setState value

Setting the default value of the value prop to an empty object caused some nested forms to have a value when they should not have one. Removing the default prop causes errors when setting the state-contained value on the parent form. So now, when creating the Immutable object to contain the form values, in the parent state, we need to ensure that props.value has value, and use an empty object if it does not.

Anticipate null value

null does not cause a parameter to use the default value, only undefined does. anticipate receiving the null object and handle by not setting state and not throwing an error.

in src/index.js

'at' function on getField object

Add a function 'at' to the object returned by getField. The 'at' function takes a string to append to the name used in getField, and returns the results of calling getField on that appended name.

checkbox method on getField for array

Add a checkbox method to the result of calling 'getField' on an array field. Checkbox accepts a string and returns a copy of the original getField properties, with the value set to the string and the checked property set according to whether or not the array contains the string.

Validation

Do you have any plans for validation implementation?

Would you be willing to share your plans for implementing the validation and accept PRs? :)

Validation API

The plan for now is that validation is declared using an array of validation config objects.

const validation = [
  {
    // name scopes validation object
    name: 'one[].two',

     // event that triggers validation function
    run: [ 'blur' ],

    // event that clears validation errors,
    clear: [ 'change' ],

    // if name not used, event that clears error, scoped to the active field
    clearSelf: [ 'focus' ],

    // function to run
    validate(formValue, fieldName, fieldValue) {

    }
  }
]

Return options from validate function

  • error string - only allowed if validation object is scoped by name
  • error object - specifies field name and error string
  • array of error objects
  • promise - promise resolves to any of the previous 3 options

The validation config array is passed as an option when wrapping component

export default FormWrapper({ validation })(MyComponent);

A validation config object can also be passed as an option in the 'field' function. In this case, scoping the config object with a name is not necessary.

const validation =   {
    run: [ 'blur' ],
    clear: [ 'change' ],
    validate(formValue, fieldName, fieldValue) {
      return !fieldValue ? "Required" : null;
    }
  }
...
<input { ...field('myField', null, { validation } ) placeholder="My Field" />

Update docs

Deprecate getName, getValue, getField. Use only 'field' API.

Include small example in main README file.

Pass props to getField

If 'getField' accepted a props object, it could set those properties on the field and add additional properties based on the type of field. For instance, { type: 'checkbox' } would enable getField to set the value and checked props on the input.

Testing

Write unit tests for existing functions

Expose update function

Allow users to import the 'update' function, in order to easily update an Immutable.js object with the JSON patch object.

Add mocha

Add mocha, expect assertion library.

onReset

Don't use the presence of props.onReset to determine whether or not to reset state.value.
If state.value, reset value.
If props.onReset, forward reset event.

Anticipate change in name prop for fieldset

All fields are cached by childname, so if the form wrapper's name prop changes, any fields accessed by the childname will be wrong. Either cache by fullname only or clear the cache when the name prop updates.

Pass plain object as props

As of React 15.1.0, a warning is displayed if the props object is not a plain JS object. The result of calling 'field' has a constructor and a prototype.

  1. Update field method so that it returns a plain object
  2. Add a new method for getting an instance of Field
  3. Add a method on Field for returning props object

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.