Giter Club home page Giter Club logo

jquery-form-helper's Introduction

Requirements

  • jQuery >= 1.10

Plugins

.populateForm(values)

Populate a form from a object. Each key for each input. The key name for the field name.

var frmValues = {"var1": "value1", "var2": "value2"};
$("#myForm").populateForm(frmValues);

.checkInput(nameCheckbox, values)

We have a checkbox array:

<label><input type="checkbox" name="myCheckbox[]" value="1"> Option 1</label>
<label><input type="checkbox" name="myCheckbox[]" value="2"> Option 2</label>
<label><input type="checkbox" name="myCheckbox[]" value="3"> Option 3</label>

Check input checkbox with name "myCheckbox" and values "1", "3" (Option 1 and Option 3)

$('#myForm').checkInput('myCheckbox', ["1", "3"]);

.checkAll(nameCheckbox, value)

We have a checkbox array:

<label><input type="checkbox" name="myCheckbox[]" value="1"> Option 1</label>
<label><input type="checkbox" name="myCheckbox[]" value="2"> Option 2</label>
<label><input type="checkbox" name="myCheckbox[]" value="3"> Option 3</label>

Check all input checkbox with name "myCheckbox"

$('#myForm').checkAll('myCheckbox', true); // for unchecked: Set false the last parameter

Check/Uncheck using another input checkbox

<!-- We need a master checkbox -->
<label><input type="checkbox" id="masterCheckbox"> Check All</label>
$('#myForm').checkAll('myCheckbox', $("#masterCheckbox")); // And here connect the master checkbox

.chainedSelect(action, jqSelect2, options)

Chain input select and populate select with result ajax.

$('#select1').chainedSelect('http://yourdomain.com/app/post.php', $('#select2'));

The $('#select2') will be populate with the response.

The response must be an array json like this:

["Option 1", "Option 2", "Option 3", ...]

or like this:

[{"value": "1", "text": "Option 1"}, {"value": "2", "text": "Option 2"}, ...]

or like this:

[{"1": "Option 2"}, {"2": "Option 2"}, {"3": "Option 3"}, ...]

In the last case use the option parameter 'keyAsValue'

$('#select1').chainedSelect('http://yourdomain.com/app/post.php', $('#select2'), {keyAsValue: true});

Options

Option Type Description
keyAsValue bool (Default: false) Populate the select using the key result as option value
data object Aditional data to send with the request
debug bool Print the response in the console on fail

Return

  • jQuery Return the second select, then we can use the return with a third select.

.submitAjax(options)

Perform an asynchronous HTTP (Ajax) request from a form.

<form action="user/save" method="post" id="myForm">
<input type="text" name="username" value="">
<input type="text" name="email" value="456">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
$('#myForm').submit(function(e){
    e.preventDefault();
    $(this).submitAjax();
});

.clickSubmit(options)

Submit all data attributes from a clickable element (anchor, button, etc.)

<a href="#" data-id="1121" class="send" data-action="http://localhost/another_app/save">Send</a>
<a href="#" data-id="1122" class="send">Send</a>
<a href="#" data-id="1123" class="send">Send</a>
$('.send').clickSubmit({action: 'http://localhost/app/save'});

.clickAjax(options)

Send an Ajax Post Request with all data attributes from a clickable element.

<a href="#" data-id="1121" class="send" data-action="http://localhost/another_app/save">Send</a>
<a href="#" data-id="1122" class="send">Send</a>
<a href="#" data-id="1123" class="send">Send</a>
var sendAjax = $('.send').clickAjax({action: 'http://localhost/app/save'});
sendAjax.done(function(r){
    console.log('Response: '+r);
});

jquery-form-helper's People

Contributors

davicotico avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.