All Projects → crapthings → Lodash Form Collector

crapthings / Lodash Form Collector

Licence: mit
a form collector powered by lodash that support any frontend framework.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lodash Form Collector

Legit
input validation framework
Stars: ✭ 81 (-19.8%)
Mutual labels:  form
Talquei
🤖 Vue components to build webforms looking like a conversation
Stars: ✭ 90 (-10.89%)
Mutual labels:  form
Formeditor
A form builder editor for Umbraco 7 - let your editors build forms easily with this free package.
Stars: ✭ 95 (-5.94%)
Mutual labels:  form
Reactjs Crud Boilerplate
Live Demo
Stars: ✭ 83 (-17.82%)
Mutual labels:  lodash
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-12.87%)
Mutual labels:  lodash
Checkout.js
💳 Quickly capture payments with the best checkout flow for crowdfunding and product launches.
Stars: ✭ 92 (-8.91%)
Mutual labels:  form
Formium
The headless form builder for the modern web.
Stars: ✭ 78 (-22.77%)
Mutual labels:  form
Formchimp
A customizable MailChimp ajax plugin for jQuery
Stars: ✭ 98 (-2.97%)
Mutual labels:  form
Formulator
A form library for Phoenix
Stars: ✭ 89 (-11.88%)
Mutual labels:  form
Purescript Halogen Formless
Painless forms for Halogen
Stars: ✭ 94 (-6.93%)
Mutual labels:  form
Dash
Functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.
Stars: ✭ 84 (-16.83%)
Mutual labels:  lodash
Immutability Helper X
The library extends the kolodny/immutability-helper to support update data by path string, like the get/set in lodash.
Stars: ✭ 86 (-14.85%)
Mutual labels:  lodash
Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (-7.92%)
Mutual labels:  form
React Native Merlin
🧙 Simple web-like forms in react native.
Stars: ✭ 83 (-17.82%)
Mutual labels:  form
Educenter Hugo
Educenter is an educational website template. It can be used as an online teaching platform, school and university websites
Stars: ✭ 96 (-4.95%)
Mutual labels:  form
Vue Rawmodel
RawModel.js plugin for Vue.js v2. Form validation has never been easier!
Stars: ✭ 79 (-21.78%)
Mutual labels:  form
Multipicker
Form styling plugin for jQuery
Stars: ✭ 90 (-10.89%)
Mutual labels:  form
Customalertviewdialogue
Custom AlertView Dialogue is the world's most advanced alert view library. Custom AlertView Dialogue includes simple message popups, confirmation alerts, selector popups, action sheet bottom menus, and input/feedback contact forms.
Stars: ✭ 100 (-0.99%)
Mutual labels:  form
Aform
AForm 是组件化、自动化、模型驱动的表单开发框架,它可以极大地提高您开发信息系统的生产力!
Stars: ✭ 96 (-4.95%)
Mutual labels:  form
Vue Typescript Music
🔥 基于 vue 全家桶 音乐项目(Music project) vue+typescript 实现 高仿 网易云音乐 移动端WebApp
Stars: ✭ 94 (-6.93%)
Mutual labels:  lodash

lodash-form-collector

NPM

demo

installation

npm i -S lodash-form-collector

import

import lfc from 'lodash-form-collector'
const lfc = require('lodash-form-collector')

usage

const form = document.getElementById('form')
const data = lfc(form)
console.log(data)

changelog

0.0.4

if you don't specify 'data-type' on input[type='checkbox'], the default data-type is set to 'boolean'. this change allow you to collect value as 'true' or 'false' as default.

HTML: Checkbox default value

### >= 0.0.4
<input type='checkbox' name='isEnabled' checked />
{ isEnable: true }
<input type='checkbox' name='isEnabled' />
{ isEnable: false }

### < 0.0.4
<input type='checkbox' name='isEnabled' checked />
{ isEnable: 'on' }
<input type='checkbox' name='isEnabled' />
{}

basic collecting


html

<form id="form">
  <input type="text" name="username" value='crapthings' />
  <input type="password" name="password" value='secret' />
  <input type="submit" />
</form>

result

{
  username: 'crapthings',
  password: 'secret'
}

collect nested field


Sets the value at path of object. If a portion of path doesn't exist, it's created. Arrays are created for missing index properties while objects are created for all other missing properties.

html

<form id="form">
  <input type="text" name="something" value="anything" />
  <input type="text" name="profile.displayName" value="crapthings" />
  <input type="text" name="profile.address.city" value="harbin" />
  <input type="number" name="profile.age" value="32" />
  <input type="radio" name="profile.gender" value="male" checked />
  <input type="radio" name="profile.gender" value="female" />
  <input type="text" name="array[0]" value="string1" />
  <input type="text" name="array[1]" value="string2" />
  <input type="text" name="sameName" value="text with same name" />
  <input type="text" name="sameName" value="will be collect as array" />
  <input type="submit" />
</form>

result

{
  something: 'anything',
  profile: {
    displayName: 'crapthings',
    address: {
      city: 'harbin'
    },
    age: 32,
    gender: 'male'
  },
  array: ['string1', 'string2'],
  sameName: ['text with same name', 'will be collect as array']
}

single checkbox with unique name


if there's a single checkbox that you want to use String as value, just write your input as normal. when it has checked, the value will present at the form result, when unchecked it won't present at result.

if there's a single checkbox that you want to use as Boolean, give your input an data attr data-type="boolean", checked = true, unchecked will collect as false.

html

<form id="form">
  <input type="checkbox" name="useValue" value="check me" checked />
  <input type="checkbox" name="bypassUnchecked" value="will not collect me" />
  <input type="checkbox" name="unchecked" data-type="boolean" />
  <input type="checkbox" name="deep.checked" data-type="boolean" checked />
  <input type="submit" />
</form>

result

{
  useValue: 'check me',
  unchecked: false,
  deep: {
    checked: true
  }
}

multiple form controls with same name


if there're multiple inputs like text that have same name. it will be collecting as array, when no values are given, it gives an empty array [].

if there're multiple checkboxes that you want to use String as value. just write your input as normal. when it has checked, the value will present at the form result. when all inputs unchecked it will be an empty array [].

html

<form id="form">
  <input type="text" name="emptyArray" />
  <input type="text" name="emptyArray" />
  <input type="email" name="emails" value="[email protected]" />
  <input type="email" name="emails" value="[email protected]" />
  <input type="checkbox" name="checkbox" value="a" checked />
  <input type="checkbox" name="checkbox" value="b" checked />
  <input type="checkbox" name="checkbox" value="c" />
  <input type="submit" />
</form>

result

{
  emptyArray: [],
  emails: ['[email protected]', '[email protected]'],
  checkbox: ['a', 'b'],
}

data type conversion


you can turn string to number or array by using data-type="number || array || [number]". text, textarea, search, hidden, select are supported.

[string separator]: text. search, hidden, options of select is ',' and textarea is '\n' by default, you can use optional by data-separator="separator".

html

<form id="form">
  <input type="text" name="textString" value="100" />
  <input type="text" name="textStringToNumber" value="100" data-type="number" />
  <input type="text" name="textStringToArray" value="100, 200, 300, 400, 500" data-type="array" />
  <input type="text" name="textStringItemOfArrayToNumber" value="100, 200, 300, 400, 500" data-type="[number]" />
  <input type="text" name="textStringItemOfArrayToNumberBySpace" value="100 200 300 400 500" data-type="[number]" data-separator=" " />
  <input type="hidden" name="hiddenString" value="100" />
  <input type="hidden" name="hiddenStringToNumber" value="100" data-type="number" />
  <input type="hidden" name="hiddenStringToArray" value="100, 200, 300, 400, 500" data-type="array" />
  <input type="hidden" name="hiddenStringItemOfArrayToNumber" value="100, 200, 300, 400, 500" data-type="[number]" />
  <input type="submit" />
</form>

result

{
  "textString": "100",
  "textStringToNumber": 100,
  "textStringToArray": ["100", "200", "300", "400", "500" ],
  "textStringItemOfArrayToNumber": [100, 200, 300, 400, 500],
  "textStringItemOfArrayToNumberBySpace": [100, 200, 300, 400, 500],
  "hiddenString": "100",
  "hiddenStringToNumber": 100,
  "hiddenStringToArray": ["100", "200", "300", "400", "500"],
  "hiddenStringItemOfArrayToNumber": [100, 200, 300, 400, 500]
}

TODOS

  • [ ] add feature data-type='object || [object]' ?
  • [ ] file to base64

FAQ

alternative

form2js

jQuery Serialize Object

might be useful

dot-object

object-path

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].