npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@comparamejor/cm-form

v1.2.15

Published

Easy antd forms managements for little and large projects

Downloads

49

Readme

cm-form ReactJS Component

Easy antd forms management for little and large projects

This component Helps you to manage antd forms for large or little projects.

How to Install?

If you're using Yarn run yarn add @comparamejor/cm-form --save else run npm i @comparamejor/cm-form -S

Dependencies

How to use it?

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import FormData from '@comparamejor/cm-form';
import 'antd/dist/antd.css';
import questions from './questions'; // Is array of the question passed to the antd form

class Form extends Component {

  /**
   * `handleSubmit:` Manage form data
   * @param {event} e event
   * */
  handleSubmit = (e) => {
    e.preventDefault();

    // Validate form data entry
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
      }
      
      // Do stuff with code here
    });
  };

  /**
   * `render:` Self descriptive
   * @return {HTML} Markup
   * */
  render() {
    return (
      <FormData
        formTitle={'Form Title'}
        questions={questions}
        onSubmit={this.handleSubmit}
        submitText={'Enviar'}
        form={this.props.form}
      />
    );
  }
}

ReactDOM.render(
  <Form />,
  document.getElementById('root')
);

Requirements

  • For correct use of the component is necessary pass the form HOC from Antd Form API.
  • questions configuration file to be passed within questions prop of the component.

FormData properties

  • questions*: array Array of questions | default []
  • formTitle?: string Form title
  • onSubmit?: func Method to manage form data
  • submitText?: string Name of send button | default 'enviar'
  • disabled?: boolean Use it for disable button after send the form
  • form: object antd form props.

Input properties

Each object within array have the next properties

  • formEntryType*: string <input|select|hiddenInput|datepicker|autocomplete|autocompleteObject|submitButton|sectionTitle|select|radioGroup|custom>
  • fieldName*: string Name for field to send
  • inputProps?: object Nature input properties [maxLength|placeholder|pattern...]
  • label?: string Name for label
  • visible?: func|boolean Validate if the input field is available to show
  • rules?: array antd form rules array of objects
  • options?: array Use this option for setting select|radioGroup options
  • addonBefore?: string Name of icon to put before input
  • vertical?: boolean Use it for layout of options type inputs
  • onChange?: func Self descriptive
  • onSelect?: func Self descriptive
  • render?: ReactJSNode return a node of React
  • extra?: ReactJSNode return a node of react as hint for the input
  • children?: use it for adding nested fields to form

Questions format

The question component property receive an array of questions or a function that returns a valid array. It would be to have a nested childs array for making actions in the form.

The format for the questions file is:

// Export as function
export default data => [
  {
    formEntryType: 'input',
    fieldName: 'firstName',
    initialValue: `${data.firstName} ${data.secondName}`,
    inputProps: {
      disabled: true,
    },
  },
  {
    formEntryType: 'input',
    fieldName: 'lastName',
    initialValue: `${data.firstSurename} ${data.secondSurename}`,
    inputProps: {
      disabled: true,
    },
  },
  {
    formEntryType: 'input',
    fieldName: 'emailAddress',
    initialValue: data.emailAddress,
    inputProps: {
      disabled: true,
    },
  },
  {
    formEntryType: 'input',
    fieldName: 'phoneMobile',
    initialValue: data.phoneMobile,
    inputProps: {
      disabled: true,
    },
  },
];

Or

// Export as array 
export default [
  {
    formEntryType: 'input',
    fieldName: 'firstName',
    inputProps: {
      disabled: true,
    },
  },
  {
    formEntryType: 'input',
    fieldName: 'lastName',
    inputProps: {
      disabled: true,
    },
  },
  {
    formEntryType: 'input',
    fieldName: 'emailAddress',
    inputProps: {
      disabled: true,
    },
  },
  {
    formEntryType: 'input',
    fieldName: 'phoneMobile',
    inputProps: {
      disabled: true,
    },
  },
];

Run tests

run yarn test