Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-rails-form-data

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-rails-form-data

React component that serializes arbitrary JS objects into hidden fields for Ruby on Rails

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

React Rails form data

standard-readme compliant

React component that serializes arbitrary JS objects into hidden fields for Ruby on Rails

Background

Created by UsabilityHub as a helper to serializes JS objects used by React into hidden form fields. The fields are named so that they are interpreted correctly by Rails. Can handle complex nested objects.

Install

npm install react-rails-form-data --save

Usage

import React from 'react'
import RailsFormData from 'react-rails-form-data'

export default class FormDataExample({ uri }) {
  const data = {
    name: 'Jane Smith',
    dateOfBirth: '1991-01-01',
    favoriteColors: ['red', 'magenta']
  }

  return (
    <form action={uri}>
      <RailsFormData path='person' data={data} />
      <button type='submit'>
        Post {data.name}'s data to {uri}.
      </button>
    </form>
  )
}
<form action='http://example.com/people'>
  <div style='display: none;'>
    <input type='hidden' name='person[name]' value='Jane Smith' />
    <input type='hidden' name='person[dateOfBirth]' value='1992-01-01' />
    <input type='hidden' name='person[favoriteColors][]' value='red' />
    <input type='hidden' name='person[favoriteColors][]' value='magenta' />
  </div>
  <button type='submit'>
    Post Jane Smith's data to http://example.com/people.
  </button>
</form>

API

RailsFormData

Create a hidden div with as many hidden fields as required.

Props
  • path: string - The key under which this object's properties will be grouped.
  • data: any - The data to group.

Contribute

Questions, bug reports and pull requests welcome. See GitHub issues.

License

MIT

Keywords

FAQs

Package last updated on 25 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc