1.3.0 • Published 8 months ago

mtforms v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

mtforms

form components for mtn sharepoint

NPM JavaScript Style Guide

Install

npm install --save mtforms

Usage

import React, { useState } from 'react'

import { Input, Select, Textarea, FormGroup, Button } from 'mtforms'
import 'mtforms/dist/index.css'

const App = () => {
  const data = [
    { item: 'test', value: 'test1' },
    { item: 'test2', value: 'test2' },
    { item: 'test3', value: 'test23' }
  ]
  const [formData, setFormData] = useState({})
  const [errors, setErrors] = useState({})

  const handleChange = (name, value) => {
    setFormData({ ...formData, [name]: value })
  }

  const submitHandler = () => {
    console.log(formData)
  }

  const validationHandler = (name, error) => {
    setErrors({ ...errors, [name]: error })
  }
  return (
    <FormGroup
      onSubmit={submitHandler}
      validation={formData}
      errors={errors}
      setErrors={setErrors}
    >
      <Input
        label='Name'
        name='firstname'
        onChange={handleChange}
        value={formData['firstname']}
        required={true}
        validationHandler={validationHandler}
        error={errors.firstname}
      />

      <Select
        className='blackBorder'
        data={data}
        required={true}
        label='Select Test'
        onChange={handleChange}
        value={formData['item']}
        name='item'
        validationHandler={validationHandler}
        error={errors.item}
        filter='item'
        filterValue='value'
      />
      <Textarea
        label='Address'
        name='address'
        onChange={handleChange}
        value={formData['address']}
        className='blackBorder'
        required={true}
        validationHandler={validationHandler}
        error={errors.address}
      />
      <Button type='submit' title='New' />
    </FormGroup>
  )
}

export default App

License

MIT © folakeyz

1.2.8

9 months ago

1.1.9

10 months ago

1.2.7

9 months ago

1.1.8

11 months ago

1.2.6

9 months ago

1.1.7

11 months ago

1.2.5

9 months ago

1.1.6

11 months ago

1.2.4

9 months ago

1.1.5

11 months ago

1.2.3

9 months ago

1.2.2

9 months ago

1.3.0

8 months ago

1.2.1

9 months ago

1.2.9

9 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.4

12 months ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.9

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago