Skip to content

Commit

Permalink
Merge pull request #224 from teads-master
Browse files Browse the repository at this point in the history
Adds filtering option
  • Loading branch information
Kevin Morris committed Feb 20, 2017
2 parents 69a0ccb + c888e76 commit bf5dc17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ beforeSubmit: function(arr, $form, options) {
}
````

###filtering
Callback function invoked before processing fiels. This provides a way to filter elements.
````javascript
filtering: function(el, index) {
if ( !$(el).hasClass('ignore') ) {
return el;
}
}
````

###clearForm
Boolean flag indicating whether the form should be cleared if the submit is successful

Expand Down
8 changes: 6 additions & 2 deletions jquery.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ $.fn.ajaxSubmit = function(options) {
}

var elements = [];
var qx, a = this.formToArray(options.semantic, elements);
var qx, a = this.formToArray(options.semantic, elements, options.filtering);
if (options.data) {
options.extraData = options.data;
qx = $.param(options.data, traditional);
Expand Down Expand Up @@ -939,7 +939,7 @@ $.fn.ajaxFormUnbind = function() {
* It is this array that is passed to pre-submit callback functions provided to the
* ajaxSubmit() and ajaxForm() methods.
*/
$.fn.formToArray = function(semantic, elements) {
$.fn.formToArray = function(semantic, elements, filtering) {
var a = [];
if (this.length === 0) {
return a;
Expand All @@ -965,6 +965,10 @@ $.fn.formToArray = function(semantic, elements) {
if (!els || !els.length) {
return a;
}

if ($.isFunction(filtering)) {
var els = $.map(els, filtering);
}

var i,j,n,v,el,max,jmax;
for(i=0, max=els.length; i < max; i++) {
Expand Down

0 comments on commit bf5dc17

Please sign in to comment.