Search code examples
jqueryjquery-pluginsjquery-forms-plugin

jQuery form plugin, ajaxForm() but with conditional fields


I need to upload a form with ajaxForm() (or so I believe, as fieldSerialize() doesn't seem to serialize file fields properly).

How can I only serialize a subset of the fields in my form using ajaxForm() ? I've tried manipulating the arr or $form parameters in beforeSerialize() or beforeSubmit() but it doesn't do it.

OR how can I use ajaxSubmit() or fieldSerialize() so that it supports file upload files as well. Lets say for EG I want to just exclude fields with the class hiddenField on it.

Thanks!


Solution

  • Wouldn't simply setting the unwanted fields to disabled solve this?

    I believe disabled fields are not submitted. See this in the jquery source code>

    serializeArray: function() {
        return this.map(function(){
            return this.elements ? jQuery.makeArray( this.elements ) : this;
        })
        .filter(function(){
            return this.name && !this.disabled &&
                ( this.checked || rselectTextarea.test( this.nodeName ) ||
                    rinput.test( this.type ) );
        })