Forms
kagd edited this page Jan 10, 2013
·
3 revisions
A collection of form methods
Generate serialized XHR2 FormData
-
data
- plain object
data = {
id: 1234567890,
person: {
first_name: 'Grant',
last_name : 'Klinsing',
meta : {
foo: 'bar',
test: [100, 200]
}
}
}
window.utilityBox.parameterizeObject(data)
generates
id = 1234567890
person[first_name] = 'Grant'
person[last_name] = 'Klinsing'
person[meta][foo] = 'bar'
person[meta][test] = [100, 200]
Serialize inputs, selects and textareas within a form
-
form
- DOM element or jQuery form element
<form action="/foobar" method="post">
<input type="text" name="foo" value="bar">
<textarea name="textarea">Hello World</textarea>
<button type="submit">Submit</button>
</form>
$(document).on 'submit', 'form', (e) ->
form = $(e.target)
obj = window.utilityBox.serializeForm(form)
Output of obj
{
foo: 'bar',
textarea: 'Hello World'
}
Automatically applies jQuery datepicker functionality to inputs with the attribute data-is="datepicker"
.
<input type="text" data-is="datepicker" value="01/01/2013">