Giter VIP home page Giter VIP logo

rform2json's Introduction

RForm2Json

A javascript library to convert any input fields to JSON.

Usage

<script type="text/javascript" src="path_to_file/RForm2Json.min.js"></script>
<script type="text/javascript>
	const jsonData = F2J(selector).getJSON(options);
</script>

Example

<div id="foo">
	<input type="text" name="key1" value="value1" />
	<input type="text" name="key2" value="value2" />
	
	<select name="key3">
		<option value="option1">Option 1</option>
		<option value="option2" selected>Option 2</option>
	</select>
	
	<input type="radio" name="key4" value="on" />
	<input type="radio" name="key4" value="off" checked />

	<input type="checkbox" name="key5" value="on" checked />
	<input type="checkbox" name="key5" value="off" />
</div>

<script type="text/javascript">
	const jsonData = F2J("#foo").getJSON();
	
	//Output:
	{
		"key1":"value1",
		"key2":"value2",
		"key3": "option2",
		"key4": "off",
		"key5": "on"
	}
</script>

Selector

Selector is any jQuery/CSS style selector which can be passed to select the element for whose inputs/fields need to be converted to JSON.

Options

  • keySelectorType(Default: "name") This option can be used to set what to type of thing to use for key's name selector. By default name attribute of the field is used.

    Possible Values - name, attribute

  • keySelector(Default:"") If keySelectorType=attribute , then this option is used to pass the name of the attribute to pick the name of the key for json.

  • valueSelectorType(Default: "value") This option can be used to set what to type of thing to use for value By default value of the field is used.

    Possible Values - value, attribute

  • valueSelector(Default: "") If valueSelectorType=attribute , then this option is used to pass the name of the attribute to pick the value for json.

  • keys(Default: []) This option is used to pass the name of the keys to be only included in the json. If suppose there are total 10 fileds in selected element, but if pass only 5 names of the keys in this option then only those key:value will be available in the final json.

  • exclude(Default: []) This option is used to pass the name of the keys to be excluded in the json. If suppose there are total 10 fileds in selected element, but if pass 2 names of the keys in this option then the passed keys will not be available in the final json.

rform2json's People

Contributors

ronit-mukherjee avatar

Stargazers

 avatar Madan Mohan Joshi avatar Ashok Vijayendra avatar  avatar

Watchers

James Cloos avatar vipulnagarwal avatar Mano Aravindhan avatar

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.