Skip to content

Add filtering option #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -59,6 +59,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

@@ -179,7 +189,7 @@ The jQuery Form plugin is dual licensed under the MIT and GPL licenses:
* [MIT](http://malsup.github.com/mit-license.txt)
* [GPL](http://malsup.github.com/gpl-license-v2.txt)

You may use either license. The MIT License is recommended for most projects because it is simple and easy to understand and it places almost no restrictions on what you can do with the plugin.
You may use either license. The MIT License is recommended for most projects because it is simple and easy to understand and it places almost no restrictions on what you can do with the plugin.

If the GPL suits your project better you are also free to use the plugin under that license.

8 changes: 6 additions & 2 deletions jquery.form.js
Original file line number Diff line number Diff line change
@@ -113,7 +113,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);
@@ -780,7 +780,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;
@@ -791,6 +791,10 @@ $.fn.formToArray = function(semantic, elements) {
if (!els) {
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++) {