Coder Social home page Coder Social logo

jquery-validate-form-submit's Introduction

Natural jQuery Form Validator

Simple html & js to use a natural jQuery validation. It natively works with bootstrap css validation.

Read Valid / Error Function Override to apply your validation system

How to use

The jQuery library is in js/jq-natural-validator.js

To use it you just add class .jqValidator as in this HTML example:

<form class="jqValidator" method="POST">
	[...]
</form>
<script>
jQuery(document).ready(function($) {
	$("form").jQNaturalValidator();
});
</script>

To validate your input fields you must add a data-attribute with a value (optional). You can see some typical integration in index.html.

Here the data-attributes list:

data-jqv-min-length				 	@default 3
data-jqv-email				 		@default true
data-jqv-not-empty				 	@default true
data-jqv-checked				 	@default true

Options

There are many simple options, if you must to add some functionality, this library was created to be easy and customizable, so ... do that!

Options:

{
    tpl: "bootstrap", 				// Bootstrap css validation class
    domFields: true, 				// Change to false to check fields on evrey validation request
    KeyPressValidation: true,		// Change to false to check form only on submit
    stepCheck: true,                // Change to false to check every input on submit (not the first wrong)
    focusOnSubmitError: true,		// Change to false to prevent autoFocus on field validation error
    disableSubmitBtnOnError: true,  // Change to false to disable submit button if form is inValid
    autoTrimCheck: true, 			// Change to false to disable autoTrim on validation check
    spinnerEl: '', 					// Inject here spinner element, at submit this will be show

    // Override submit Function (example: inject an ajax send function)
    submitFunction: '',

    // Override validtion Function (@params: el, validation_type ['submit' | 'keyPress' | 'testSubmit'])
    validFieldFunction: '', 		// Override default bootstrap validField css with you Function

    // Override error Function (@params: el, validation_type ['submit' | 'keyPress' | 'testSubmit'])
	errorFieldFunction: '', 		// Override default bootstrap errorField css with you Function

    // [data-*] get validation opts from html attributes
	attrs: {
		"jqv-min-length": 3,
		"jqv-email": true,
		"jqv-not-empty": true,
		"jqv-checked": true
	},

	// Main regex (used with some field validation)
	regex: {
		email: /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	}
}

Valid / Error Function Override

To add your favourite validation system edit this plugin at base.validFieldWrapper and base.errorFieldWrapper or better use options validFieldFunction and validFieldFunction to inject your function without edit this library.

A simple custom validation example:

<script>
var validFunction = function() { alert('valid'); }
var errorFieldFunction = function() { alert('error'); }
jQuery(document).ready(function($) {
	$("form.jqValidator").jQNaturalValidator({
		validFieldFunction: validFunction,
		errorFieldFunction: errorFieldFunction
	});
});
</script>

Add a spinner at submit

Spinner integration example:

<script>
jQuery(document).ready(function($) {
	$("form").jQNaturalValidator({
		spinnerEl: $("form #spinner")
	});
});
</script>

Override the custom submit function (usefull on ajax data submit)

An ajax submit Function example:

<script>
jQuery(document).ready(function($) {
	$("form").jQNaturalValidator({
		submitFunction: function() {
			$.ajax({
				url: "save.php",
				type: "POST",
				data: {
					name:  $("#name").val(),
					email: $("#email").val()
				}
			})
			.success(function(result) { alert("data saved"); })
		}
	});
});
</script>

jquery-validate-form-submit's People

Contributors

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