Created
February 22, 2013 03:31
-
-
Save MaraScott/5010513 to your computer and use it in GitHub Desktop.
Name : checkForSubmit(o, fields) - Language : javascript - type : function - platform : jQuery - tag :
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
| function checkForSubmit(o, fields) { | |
| "use strict"; | |
| var submit = true; | |
| var form = o.parents('form:eq(0)'); | |
| form.submit(function() { | |
| if (typeof fields !== 'undefined') { | |
| if (typeof fields.input !== 'undefined') { | |
| if (typeof fields.input.text !== 'undefined') { | |
| var text = fields.input.text; | |
| for (var i = 0, len = text.length; i < len; ++i) { | |
| if (jQuery(text[i][0]).val() === text[i][1] || jQuery(text[i][0]).val() === '') { | |
| submit = false; | |
| } | |
| } | |
| } else { | |
| submit = false; | |
| } | |
| } else { | |
| submit = false; | |
| } | |
| } else { | |
| submit = false; | |
| } | |
| console.log(submit); | |
| return submit; | |
| }); | |
| } | |
| var fieldsToCheck = { | |
| "input": { | |
| "text": [ | |
| ["inputCssSelector", "Default Value"] | |
| ] | |
| } | |
| }; | |
| $('#idSubmitButton').click(function() { | |
| "use strict"; | |
| checkForSubmit($(this), fieldsToCheck); | |
| }); | |
| /* | |
| function checkForSubmit(o) { | |
| "use strict"; | |
| submit = 1; | |
| form = o.parents('form:eq(0)'); | |
| form.find('.required input').each(function(e) { | |
| if ($(this).val() == '') { | |
| $(this).css('border', '#ea3232 1px solid'); | |
| submit = 0; | |
| } else { | |
| $(this).css('border', '#39BACD 1px solid'); | |
| } | |
| }); | |
| form.find('.required select option::selected').each(function(e) { | |
| if ($(this).val() == 0) { | |
| $(this).parent().css('border', '#ea3232 1px solid'); | |
| submit = 0; | |
| } else { | |
| $(this).parent().css('border', '#39BACD 1px solid'); | |
| } | |
| }); | |
| if (submit) { | |
| form.attr('action', form.find('.required input[name="linkForm"]').val()); | |
| form.submit(); | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment