Angular like reactive forms in React.

Overview

React Native Game Engine

React Reactive Forms

Build Status Backers on Open Collective Sponsors on Open Collective NPM Version code style: prettier gzip size PRs welcome

It's a library inspired by the Angular's Reactive Forms, which allows to create a tree of form control objects in the component class and bind them with native form control elements.

Features

  • UI independent.
  • Zero dependencies.
  • Nested forms.
  • Subscribers for value & status changes of controls.
  • Provides a set of validators & also supports custom sync & async validators.
  • FormGenerator api to create large forms with less code.
  • Better form management with FormGroup & FormArray apis.
  • Customizable update strategy for better performace with large forms.

Installation

npm install react-reactive-form --save

Basic Example

import React, { Component } from 'react';
import {
    FormBuilder,
    FieldGroup,
    FieldControl,
    Validators,
 } from "react-reactive-form";

const TextInput = ({ handler, touched, hasError, meta }) => (
  <div>
    <input placeholder={`Enter ${meta.label}`} {...handler()}/>
    <span>
        {touched
        && hasError("required")
        && `${meta.label} is required`}
    </span>
  </div>  
)
export default class Login extends Component {
    loginForm = FormBuilder.group({
        username: ["", Validators.required],
        password: ["", Validators.required],
        rememberMe: false
    });
    handleReset=() => {
        this.loginForm.reset();
    }
    handleSubmit=(e) => {
        e.preventDefault();
        console.log("Form values", this.loginForm.value);
    }
    render() {
        return (
              <FieldGroup
                control={this.loginForm}
                render={({ get, invalid }) => (
                  <form onSubmit={this.handleSubmit}>

                    <FieldControl
                      name="username"
                      render={TextInput}
                      meta={{ label: "Username" }}
                    />

                    <FieldControl
                      name="password"
                      render={TextInput}
                      meta={{ label: "Password" }}
                    />

                    <FieldControl
                      name="rememberMe"
                      render={({handler}) => (
                        <div>
                          <input {...handler("checkbox")}/>
                        </div>
                      )}
                    />
                    <button
                      type="button"
                      onClick={this.handleReset}
                    >
                      Reset
                    </button>
                    <button
                      type="submit"
                      disabled={invalid}
                    >
                      Submit
                    </button>
                  </form>
                )}
              />
        );
    }
}

Using FormGenerator

import React, { Component } from 'react';
import {
    Validators,
    FormGenerator
 } from "react-reactive-form";
// Input component
const TextInput = ({ handler, touched, hasError, meta }) => (
  <div>
    <input placeholder={`Enter ${meta.label}`} {...handler()}/>
    <span>
        {touched
        && hasError("required")
        && `${meta.label} is required`}
    </span>
  </div>  
)
// Checkbox component
const CheckBox = ({ handler }) => (
    <div>
      <input {...handler("checkbox")}/>
    </div>
  )
// Field config to configure form
const fieldConfig = {
    controls: {
        username: {
            options: {
                validators: Validators.required
            },
            render: TextInput,
            meta: { label: "Username" }
        },
        password: {
            options: {
                validators: Validators.required
            },
            render: TextInput,
            meta: { label: "Password" }
        },
        rememberMe: {
            render: CheckBox
        },
        $field_0: {
            isStatic: false,
            render: ({ invalid, meta: { handleReset } }) => (
                <div>
                    <button
                      type="button"
                      onClick={handleReset}
                    >
                      Reset
                    </button>
                    <button
                      type="submit"
                      disabled={invalid}
                    >
                      Submit
                    </button>
                </div>
            )
        }
    },
}
export default class Login extends Component {
    handleReset=() => {
        this.loginForm.reset();
    }
    handleSubmit=(e) => {
        e.preventDefault();
        console.log("Form values", this.loginForm.value);
    }
    setForm = (form) => {
        this.loginForm = form;
        this.loginForm.meta = {
            handleReset: this.handleReset
        }
    }
    render() {
        return (
            <form onSubmit={this.handleSubmit}>
                <FormGenerator
                    onMount={this.setForm}
                    fieldConfig={fieldConfig}
                />
            </form>
        );
    }
}

Add Controls Dynamically

You can also create controls without even initializing the group control object with the help of new react form components ( FieldGroup, FieldControl, FieldArray).

import React, { Component } from 'react'
import { FieldGroup, FieldControl, Validators } from 'react-reactive-form'

export default class Login extends Component {
  handleSubmit = (e, value) => {
    console.log('Form values', value)
    e.preventDefault()
  }
  render() {
    return (
      <FieldGroup
        render={({ get, invalid, reset, value }) => (
          <form onSubmit={e => this.handleSubmit(e, value)}>
            <FieldControl
              name="username"
              options={{ validators: Validators.required }}
              render={({ handler, touched, hasError }) => (
                <div>
                  <input {...handler()} />
                  <span>
                    {touched && hasError('required') && 'Username is required'}
                  </span>
                </div>
              )}
            />
            <FieldControl
              name="password"
              options={{ validators: Validators.required }}
              render={({ handler, touched, hasError }) => (
                <div>
                  <input {...handler()} />
                  <span>
                    {touched && hasError('required') && 'Password is required'}
                  </span>
                </div>
              )}
            />
            <FieldControl
              name="rememberMe"
              render={({ handler }) => (
                <div>
                  <input {...handler('checkbox')} />
                </div>
              )}
            />
            <button type="button" onClick={() => reset()}>
              Reset
            </button>
            <button type="submit" disabled={invalid}>
              Submit
            </button>
          </form>
        )}
      />
    )
  }
}

So, it's not mandatory that you need to define your control separately but if you want a better control over your form state then you should do that, if your controls are dynamic then you can also initalize the empty group control and add the controls later. See the example:

import React, { Component } from 'react'
import {
  FormBuilder,
  FieldGroup,
  FieldControl,
  Validators
} from 'react-reactive-form'

export default class Login extends Component {
  // Initialize the empty group control
  loginForm = FormBuilder.group({})

  handleReset = e => {
    this.loginForm.reset()
  }
  handleSubmit = e => {
    console.log('Form values', this.loginForm.value)
    e.preventDefault()
  }
  render() {
    return (
      <FieldGroup
        control={this.loginForm}
        render={({ get, invalid, reset, value }) => (
          <form onSubmit={this.handleSubmit}>
            <FieldControl
              name="username"
              options={{ validators: Validators.required }}
              render={({ handler, touched, hasError }) => (
                <div>
                  <input {...handler()} />
                  <span>
                    {touched && hasError('required') && 'Username is required'}
                  </span>
                </div>
              )}
            />
            <FieldControl
              name="password"
              options={{ validators: Validators.required }}
              render={({ handler, touched, hasError }) => (
                <div>
                  <input {...handler()} />
                  <span>
                    {touched && hasError('required') && 'Password is required'}
                  </span>
                </div>
              )}
            />
            <FieldControl
              name="rememberMe"
              render={({ handler }) => (
                <div>
                  <input {...handler('checkbox')} />
                </div>
              )}
            />
            <button type="button" onClick={this.handleReset}>
              Reset
            </button>
            <button type="submit" disabled={invalid}>
              Submit
            </button>
          </form>
        )}
      />
    )
  }
}

Documentation

Code Sandboxes

Try out react-reactive-forms in these sandbox versions of the Examples.

FAQ

How is it different from other form libraries?

React has many libraries which works on the form logic, but here are some concerns with these:

Code Complexity

If you’re using the redux-form then you should know the pain, for just a two field login form you’d to write the store logic.In RRF you can see that how simple is to deal with simple and complex forms.

And one of the awesome thing is that you can just write your form controls logic anywhere in your application.

Dependencies

Many libraries come with dependencies for e.g redux is required for redux-form, So what If I’m using another state management or not event using any. According to Dan Abramov, form state is inherently ephemeral and local, so tracking it in Redux (or any kind of Flux library) is unnecessary. RRF comes with zero dependency, So it’s totally up to you that how you want to save your form state if needed.

Performance

Now that’s a big problem with almost all libraries when you're dealing with large forms.

How RRF does solve performance issues ?

  • It uses subscription to update the components so rather updating all the fields on every input changes, it only update the particular field for which the state change takes place.
  • RRF has a nice option to define that when(blur, submit or change) to update your form's state by using the updateOn property.

Dynamic Changes

With the help of subscribers it's pretty easy to listen for a particular state changes and modify the controls accordingly.

What are value and status changes subscribers?

RRF uses inbuilt Subject, A Subject is an object with the method next(v).To feed a new value to the Subject,RRF just calls the next(theValue), and it will be multicasted to the Observers registered to listen to the Subject. So basically it provides three subjects for each AbstractControl valueChanges, statusChanges and stateChanges and additional two subjects for FormControl ( onValueChanges, onBlurChanges) You can register an observer to a particular Subject to do some actions whenever some particular changes happen.

Example:

componentDidMount() {
  this.myForm.get(“gender”).valueChanges.subscribe((value) => {
    // do something
  })
}

Checkout the Basic usage guide for more details.

How the Field components work?

Field components are subscribed to the state changes of a particular control which means that it’ll re-render the component only when it’s state changes disregarding of other field changes.You can also implement your custom wrappers by using the stateChanges Subject.

How updateOn feature works?

Its an another performance booster in RRF, it just holds the computation needed to be made after every keystroke or value changes until you want to execute.It has three options change(default), blur and submit, you can define all of them at both field and record level.

Is this library compatible with React Native?

Yes, this library works with react-native also, currently it supports react-native TextInput and Switch component.

Note:

If you're using react-native then please add the following line of code in index.js of your project to avoid error in android devices.

import "core-js/es6/symbol";
import "core-js/fn/symbol/iterator";

Let's make React Reactive Forms better! If you're interested in helping, all contributions are welcome and appreciated.

And don't forget to star the repo, I will ensure more frequent updates! Thanks!

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Comments
  • markAsUntouched() / markAsPrestine() doesn't update invalid/dirty on submit button.

    markAsUntouched() / markAsPrestine() doesn't update invalid/dirty on submit button.

    Hello,

    I'm having an issue where I want the submit button to re-disable once a form is submitted. In my submithandler I'm calling markAsUntouched() on the form, if I console.log the entire form after I can see that dirty is set to false again however the button never seems to get the updated value and stays enabled.

    My render looks like this: render={({ get, invalid, dirty }) => { And my button: <button type="submit" disabled={invalid || !dirty}>

    I have no clue how to (quickly) setup a plunker (or whatever) to demonstrate the issue but I did mess around in the codesandbox.io examples and I can't seem to get it to function in there either.

    Kind regards, Jan-Jelles van Stormbroek

    enhancement 
    opened by Bullace 11
  • Creating a list of checkboxes with a toggle

    Creating a list of checkboxes with a toggle

    I've been looking through the documentation as wel as the examples and the source code, but there's something I can't figure out and that is how to have a group of checkboxes that I can all check or uncheck by the click of a button.

    I have the following:

    const cfg = {
      address: '',
      priority: '',
      state: FormBuilder.array([]),
    };
    
    const filterForm = FormBuilder.group(cfg);
    

    In my component's constructor:

      this.props.statusList.forEach((status) => { // statusList is an array of objects with props 'key' and 'value'
       filterForm.get('sstate').push(FormBuilder.control(status));
      });
    

    And in my render() function:

    <FieldGroup
      control={this.filterForm}
      render={({ invalid }) => (
      <FieldArray
          render={({ controls }) => {
            return (
              <Fragment>
                <button type="button" onClick={() => { }}> // toggle button
                  Alles
                </button>
    
                {controls.map((statusControl, index) => {
                  return (
                    <FieldControl
                      key={`${statusControl}${index}`} // eslint-disable-line
                      control={statusControl}
                      render={({ handler, parent, setValue, stateChanges }) => {
                        const { key, value } = handler().value;
    
                        return (
                          <div key={key}>
                            <input
                              id={`${name}-${key}`}
                              name="state"
                              type="checkbox"
                              value={key}
                            />
    
                            <label htmlFor={`${name}-${key}`}>
                              {value}
                            </label>
                          </div>
                        );
                      }}
                    />
                  );
                })}
              </Fragment>
            );
          }}
          name="state"
        />
      )}
    />
    

    Two issues here:

    • when I submit the form, I don't see the value for the checked boxes; I see all the values for all of them
    • the onClick handler that I want to toggle all of the boxes doesn't seem to work with React's useState hook

    How can I solve both issues mentioned? Feedback greatly appreciated.

    opened by janjaap 6
  • Can't add separate Fields

    Can't add separate Fields

    Describe the bug I use FormGenerator. And I customized my form component and used it. But when I use separate fields it's render just first one. I changed order of fields but just first one on dialog

    Screenshots image

    Desktop (please complete the following information):

    Additional context how I create:

    controls: {
            autosuggestion: {
                render: (control) => <AutocomplateField {...control} />,
                meta : {
                    label: "some"
                }
            },
            downshift: {
                render: (control) => <IntegrationDownshift {...control}/>,
                meta: {
                    label: 'downshift'
                }
            }
        }
    
    opened by aturan23 6
  • React is outdated in console getting warnings

    React is outdated in console getting warnings

    react-dom.development.js:67 Warning: Legacy context API has been detected within a strict-mode tree.

    The old API will be supported in all 16.x releases, but applications using it should migrate to the new version.

    Please update the following components: FieldControl, FieldGroup

    opened by vforv 5
  • Warning: Legacy context API has been detected within a strict-mode tree.

    Warning: Legacy context API has been detected within a strict-mode tree.

    Warning: Legacy context API has been detected within a strict-mode tree.
    
    The old API will be supported in all 16.x releases, but applications using it should migrate to the new version.
    
    Please update the following components: FieldControl, FieldGroup
    
    opened by devnoot 5
  • How to render form on state/prop change - strict = false

    How to render form on state/prop change - strict = false

    Describe the bug I am trying to pass some props/state to the form. I call useEffect' to set the info but the form does not re-render. I have setstrict` to false in both FieldGroup and FieldControl - I am not sure what I am missing.

    I have made a sandbox here

    In the sample code below which is what is in sandbox I am calling useEffect to set a variable that I want passed as the value of one of my form inputs. The default value is 'foo' and I want the form to show the updated state 'bar'. How can I achieve this?

    Sample Code

    import React, { useState, useEffect } from 'react'
    
    import {
      FieldControl,
      FieldGroup,
      FormControl,
      FormGroup
    } from 'react-reactive-form'
    
    const TextInput = ({
      meta,
      handler
    }) => (
    <>
      <labeL>{meta.placeholder}</labeL>
      <input {...handler()} />
      </>
    )
    
    const MyForm = (props) => {
      useEffect(() => {
        setStickerStyle('bar')
      }, [])
    
      const [stickerStyle, setStickerStyle] = useState('foo')
    
      const myForm = new FormGroup({
        style: new FormControl(stickerStyle)
      })
    
      const handleSubmit = (e) => {
        e.preventDefault()
      }
    
      return (
        <>
           <form onSubmit={() => handleSubmit}>
             <h1>{stickerStyle}</h1>
             <FieldGroup
               strict={false}
               control={myForm}
               render={({ invalid, pristine, pending, value }) => (
                 <div>
                   <FieldControl
                     strict={false}
                     name="style"
                     render={TextInput}
                     meta={{ placeholder: 'This should be "bar" and not "foo"' }}
    
                   />
                   <pre>{JSON.stringify(value, 0, 2)}</pre>
                 </div>
               )}
             />
           </form>
    
        </>
      )
    }
    
    export default MyForm
    

    Version: 1.0.30"

    opened by cyberwombat 5
  • How to implement Radio button with Reactive-Forms in React Native

    How to implement Radio button with Reactive-Forms in React Native

    Actually, I want to implement the Radio button in React Native.

    I tried to display Radio buttons on the UI and rendred under Field Control. but when I am selecting another radio button Form Control render is not re-rendred.

    opened by Dhirajbhujbal 4
  • isRequired flag in FormGenerator controls to show asterisk (*) in label

    isRequired flag in FormGenerator controls to show asterisk (*) in label

    Hi i am using FormGenerator API for my form i want to show the asterisk (*) on label if the control is required but could not find a flag in render args, could anyone please guide?

    opened by arahmanali 4
  • in select box value is not populating when i use input box value is populating

    in select box value is not populating when i use input box value is populating

    hi @bietkul, Small quick help,

    i have one form after submitting the form am storing the data,while edit mode in select box, value is not populating when i use input box its populating.please update me what is causing issue please find the below code.

    <FieldControl name="dbName" strict={false} render={({ handler, touched, hasError }: AbstractControl) => (

    <select className={form-control} {...handler()} />

                                            <div className="invalid-form">
                                                {touched
                                                    && hasError('required')
                                                    && 'Database name is required'}
                                            </div>
                                           
                                        </div>
                                    )}
                                /> 
    
    opened by sred36 4
  • Unable to install in project with react 18.2

    Unable to install in project with react 18.2

    npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: [email protected] npm ERR! Found: [email protected] npm ERR! node_modules/react npm ERR! [email protected]"^18.2.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer [email protected]"^15.0.0-0 || ^16.4.0-0" from [email protected] npm ERR! node_modules/react-reactive-form npm ERR! [email protected]"*" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

    opened by codebysandip 3
  • Validator for password not working on react native

    Validator for password not working on react native

    I am working on latest react-native version. I'm trying to implement a custom validator to check if the password and password confirm are equal. The problem is that the validator function is not working.

    Code::

    MatchPassword(AC: AbstractControl) {
      let password = AC.get('new_password').value; // to get value in input tag
      let confirmPassword = AC.get('confirm_password').value; // to get value in input tag
      if (password !== confirmPassword) {
        AC.get('confirm_password').setErrors({ mismatch: true });
      } else {
        return null;
      }
    }
    
    changePasswordForm = FormBuilder.group({
      new_password: ['', [Validators.required]],
      confirm_password: ['', [Validators.required]],
    }, {
      validator: this.MatchPassword,
    });
    
    render() {
    return (
        <Fragment>
            <FieldGroup
                control={this.changePasswordForm}
                render={() => {
                    return (
                        <Fragment>
                            <FieldControl
                                name="new_password"
                                render={({ handler, touched, hasError, ...props }) => (
                                    <Fragment>
                                        <TextInput {...props} label="New Password" placeholder="Password" handler={handler} type="password" secureTextEntry  />
                                        {(touched && hasError('required')) && <ErrorText message="This Field Should Not Be Empty." />}
                                    </Fragment>
                                )}
                            />
                            <FieldControl
                                name="confirm_password"
                                render={({ handler, touched, hasError, ...props }) => (
                                    <Fragment>
                                        <TextInput {...props} label="Confirm Password" placeholder="Confirm Password" handler={handler} type="password" secureTextEntry />
                                        {(touched && hasError('required')) && <ErrorText message="This Field Should Not Be Empty." />}
                                        {(touched && hasError('mismatch')) && <ErrorText message="Password No Match!" />}
                                    </Fragment>
                                )}
                            />
    
                            <Button onPress={() => this.handleSubmit()} variant="success" block large style={[mb0, mr15, flex1]}>Submit</Button>
                        </Fragment>
                    );
                }}
            />
        </Fragment>
    );
    }
    

    Please tell me how to do this?

    opened by harleenarora 3
  • Bump decode-uri-component from 0.2.0 to 0.2.2

    Bump decode-uri-component from 0.2.0 to 0.2.2

    Bumps decode-uri-component from 0.2.0 to 0.2.2.

    Release notes

    Sourced from decode-uri-component's releases.

    v0.2.2

    • Prevent overwriting previously decoded tokens 980e0bf

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2

    v0.2.1

    • Switch to GitHub workflows 76abc93
    • Fix issue where decode throws - fixes #6 746ca5d
    • Update license (#1) 486d7e2
    • Tidelift tasks a650457
    • Meta tweaks 66e1c28

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump loader-utils from 2.0.2 to 2.0.4

    Bump loader-utils from 2.0.2 to 2.0.4

    Bumps loader-utils from 2.0.2 to 2.0.4.

    Release notes

    Sourced from loader-utils's releases.

    v2.0.4

    2.0.4 (2022-11-11)

    Bug Fixes

    v2.0.3

    2.0.3 (2022-10-20)

    Bug Fixes

    • security: prototype pollution exploit (#217) (a93cf6f)
    Changelog

    Sourced from loader-utils's changelog.

    2.0.4 (2022-11-11)

    Bug Fixes

    2.0.3 (2022-10-20)

    Bug Fixes

    • security: prototype pollution exploit (#217) (a93cf6f)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • using FormGenerator example doesnt work

    using FormGenerator example doesnt work

    this example doesnt work https://github.com/bietkul/react-reactive-form#using-formgenerator when you submit for the results are empty

    • copy code in new project
    • run code
    • fill in the form with values
    • hit submit, results
    Screenshot 2022-11-07 at 15 06 36
    opened by loekTheDreamer 0
  • Add wrapper around nested controls with FormGenerator

    Add wrapper around nested controls with FormGenerator

    Hello,

    I have this dynamically build fieldConfig and I have nested controls inside, see phoneNumberRow prop. How can I render the form with a div around the two controls phoneNumberPrefix and phoneNumber ?

    const fieldConfig = {
      "civility": {
        "meta": {
          "label": "Title",
          "name": "civility",
          "type": "hidden"
        }
      },
      "firstName": {
        "meta": {
          "label": "First name",
          "name": "firstName",
          "type": "text"
        }
      },
      "lastName": {
        "meta": {
          "label": "Surname",
          "name": "lastName",
          "type": "text"
        }
      },
      "phoneNumberRow": {
        "controls": {
          "phoneNumberPrefix": {
            "meta": {
              "label": "Phone code",
              "name": "phoneNumberPrefixChoiceList",
              "optionList": [
                {
                  "value": "ad_376",
                  "textLabel": "+376",
                  "listTextLabel": "+376 (Andorra)"
                },
                {
                  "value": "au_61",
                  "textLabel": "+61",
                  "listTextLabel": "+61 (Australia)"
                },
                {
                  "value": "at_43",
                  "textLabel": "+43",
                  "listTextLabel": "+43 (Austria)"
                }
              ]
            }
            "formState": "au_61"
          },
          "phoneNumber": {
            "meta": {
              "label": "Mobile number",
              "name": "phoneNumber",
              "type": "number"
            }
          }
        }
      },
      "company": {
        "meta": {
          "label": "Company (optional)",
          "name": "company",
          "type": "text"
        }
      }
    }
    
    opened by arthurhamon 0
  • To remove multiple controls from dynamic FormArray not working with removeAt

    To remove multiple controls from dynamic FormArray not working with removeAt

    Describe the bug To remove multiple controls from dynamic FormGroup not working with removeAt. My case i want to remove multiple FormControls from FormGroup then need to push new multiple FormControls in the same FormGroup. At that time removeAt will not worked.

    If i loop through my FormGroup & try to use removeAt it will execute only one time then break the loop, also i have other logic codes below that also not executable.

    I tried like below code,

    control.meta.currentForm.controls['dynamicSelector']['controls'].forEach((child, index) => { child.removeAt(index); });

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by MartinJesu 0
Releases(1.0.28)
Owner
Kuldeep Saxena
Kuldeep Saxena
📋 React Hooks for forms validation (Web + React Native)

Version 7 | Version 6 English | 日本語 Features Built with performance, UX and DX in mind Embraces native form validation Out of the box integration with

React Hook Form 32.6k Jan 8, 2023
Build forms in React, without the tears 😭

Build forms in React, without the tears. Visit https://formik.org to get started with Formik. Organizations and projects using Formik List of organiza

Formium 31.7k Dec 31, 2022
Forms library for react-native

Notice tcomb-form-native is looking for maintainers. If you're interested in helping, a great way to get started would just be to start weighing-in on

Giulio Canti 3.2k Dec 17, 2022
A simple, declarative API for creating cross-platform, native-appearing forms with React Native

React Native Forms Project status I wrote this library several (many?) years ago for a use-case at work, when React Native was still quite young, comp

Michael Helvey 87 Jul 10, 2022
React component for convert the valle screens-api data structure to web component based forms.

valleForm React component for convert the valle screens-api data structure to web component based forms. Write <valleForm tabs = { [...] } but

Valle Sistemas de Gestão 7 Dec 16, 2021
Generate forms with native look and feel in a breeze

React Native Form Generator Generate forms with native look and feel in a breeze Components Picker DatePicker TimePicker Input Link Separator Switch F

Michael Cereda 375 Dec 7, 2022
Handle your forms in a smart way

react-native-form-builder Note: If you're looking for a better form management library with more advanced features, Please check out React Reactive Fo

Kuldeep Saxena 117 Jul 24, 2022
📝 Form component for React Native.

Gifted Form Form component for React Native. Example var { GiftedForm, GiftedFormManager } = require('react-native-gifted-form'); var FormComponent =

Farid Safi 1.4k Dec 19, 2022
A simple react-native component to wrap your form fields and get their values with just one single method.

react-native-form A simple react-native component to wrap your form fields and get their values without attaching listeners everywhere. Installation n

Juliano Duarte 145 Nov 11, 2022
Simple form validation library for React Native.

Foect Simple form validation library for React Native. Installing Npm npm i --save foect Yarn yarn add foect Quick Start import { TextInput, Text, V

null 38 Nov 11, 2022
FM Form is a module for React Native to fast generate pages with a form.

react-native-fm-form FM Form is a module for React Native to fast generate pages with a form. It works like Backbone forms. Using this module you can

Yi Wang 13 Dec 9, 2021
A simple validation library for react native

react-native-form-validator A simple validation library for react native Installation Run: $ npm i react-native-validation --save Validators: matchReg

Şerafettin Aytekin 14 Mar 25, 2021
Project using React Router, Styled Components, useEffect, useState and context

Before run do the steps bellow install npm or yarn To run this application you can just use npm or if you want, yarn is another option. Download NPM I

Guilherme Mello 0 Dec 29, 2021
Angular like reactive forms in React.

React Reactive Forms It's a library inspired by the Angular's Reactive Forms, which allows to create a tree of form control objects in the component c

Kuldeep Saxena 290 Nov 26, 2022
Inventory App - a SPA (Single Page Application) project developed with Angular using Reactive Forms and VMware's Clarity components.

InventoryApp This project was generated with Angular CLI version 13.0.1. Development server Run ng serve for a dev server. Navigate to http://localhos

null 11 Oct 5, 2022
(Angular Reactive) Forms with Benefits 😉

(Angular Reactive) Forms with Benefits ?? How many times have you told yourself "I wish Angular Reactive Forms would support types", or "I really want

ngneat 583 Dec 28, 2022
Implementation Angular 13 Form Validation with Submit using Reactive Forms Module and Bootstrap 4.

Implementation Angular 13 Form Validation with Submit using Reactive Forms Module and Bootstrap 4. The form has: Full Name: required Username: require

Meher 1 May 5, 2022
Consuming series data from marvel api and implementing features like infinite scroll, reactive search and lazy loading on images with Angular.

Consuming series data from marvel api and implementing features like infinite scroll, reactive search and lazy loading on images with Angular.

Renato Curcino Barros 1 Jul 19, 2022
Class Reactive is a utility library that endore multiple programing principles like (Separate of concern, DDD, reactive).

Class Reactive Class Reactive is a utility library that endore multiple programing principles like (Separate of concern, DDD, reactive). Design mainly

null 1 May 12, 2022
A small Angular library that lets you use React components inside Angular projects

React in Angular and Angular in React This is a small Angular library that lets you use React components inside Angular projects. <react-wrapper [comp

BubblyDoo 9 Oct 18, 2022