GitXplorerGitXplorer
m

jquery-widgetize-form

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
c067628c1ce29220362a78cab05a4387c326c4c5

Adding license to the releases' headers.

mmpavelka committed 8 years ago
Unverified
f0d87c9e19e3e03509991672c548e21313301aed

Adding README

mmpavelka committed 8 years ago
Unverified
3535602d97ec96db4b8662b26c061427aba3ccbf

Adding new option for users to define custom getData function.

mmpavelka committed 8 years ago
Unverified
aa7a386444056227f25e85f6dd49368bbeb98dca

Integrating gulp.

mmpavelka committed 8 years ago
Unverified
659944168c074221a446c62f0626d81d1763e1a9

Adding minified version

mmpavelka committed 8 years ago
Unverified
0cbfddcce22992ad566ae34152ca1f4fcbcecb69

Displaying field errors from response object.

mmpavelka committed 8 years ago

README

The README file for this repository.

jQuery Widgetize Form

This plugin converts a regular HTML form into an interactive widget that submits data over AJAX and displays messages.

Usage

Let's assume you have a form like this

<form id="my-form" action="/some/action" method="POST">
	<div class="messages form-group">
	</div>
	<div class="form-group">
		<label for="exampleInputEmail1">Email address</label>
		<input type="email" class="form-control" name="email" placeholder="Email">
		<div class="input-error">
		</div>
	</div>
	<div class="form-group">
		<label for="exampleInputPassword1">Password</label>
		<input type="password" class="form-control" name="password" placeholder="Password">
	</div>
	<button type="submit" class="btn btn-default">Submit</button>
</form>

You can make this form submit data via AJAX request by calling

$('#my-form').widgetizeForm();

When you submit the form, the form data will be converted to JSON and sent to the url specified in the action attribute of the form.

Options

There are several options of setting up the form. Here are the defaults

$(form).widgetizeForm({
	inputWrapper: '.form-group',
	errorWrapper: '.input-error',
	messageWrapper: '.messages',
	hasErrorClass: 'has-error',
	errorClass: 'help-inline help-alert',
	response: {
		keyMessage : "message",
		keyErrors: "errors"
	},
	messages: {
		fromResponse: false,
		classSuccess: 'alert alert-success',
		classError: 'alert alert-danger',
		success: "Success!",
		error: "There is an error in sent data.",
		serverError: "Server encountered an error.",
		connectionRefused: "Connection refused."
	},
	resetOnSuccess: true,
	onSuccess: null,
	onError: null,
	getData: null,
});