Created
July 21, 2014 14:39
-
-
Save biohzrdmx/7680abeb221dc9adb1ee to your computer and use it in GitHub Desktop.
Form handlers (validator + jquery-form)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('form[data-submit=validate]').on('submit', function() { | |
| var form = $(this); | |
| return form.validate({ | |
| error: function(fields) { | |
| fields.each(function() { | |
| var field = $(this); | |
| field.closest('.form-group').addClass('has_error'); | |
| field.on('focus', function() { | |
| field.closest('.form-group').removeClass('has_error'); | |
| field.off('focus'); | |
| }); | |
| }); | |
| } | |
| }); | |
| }); | |
| $('form[data-submit=ajax]').each(function() { | |
| var form = $(this); | |
| form.ajaxForm({ | |
| dataType: 'json', | |
| beforeSubmit: function() { | |
| return form.validate({ | |
| success: function() { | |
| form.find('input, select').prop({ disabled: true }); | |
| form.find('button[type=submit]').prop({ disabled: true }).loading({ text: 'Enviando...' }); | |
| }, | |
| error: function(fields) { | |
| fields.each(function() { | |
| var field = $(this); | |
| field.closest('.form-group').addClass('has_error'); | |
| field.on('focus', function() { | |
| field.closest('.form-group').removeClass('has_error'); | |
| field.off('focus'); | |
| }); | |
| }); | |
| } | |
| }); | |
| }, | |
| success: function(response) { | |
| form.clearForm(); | |
| form.find('input, select').prop({ disabled: false }); | |
| form.find('button[type=submit]').prop({ disabled: false }).loading('done'); | |
| $.alert('Gracias por tus comentarios'); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment