Skip to content

Added required attribute value of input elements to formToArray return object #189

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
Apr 6, 2012

Conversation

collingo
Copy link
Contributor

@collingo collingo commented Apr 4, 2012

Hi,

I added the HTML5 required attribute value to the formToArray function. I found this helpful when using the beforeSubmit callback for validation. The required property is defined once in the html and can then be handled with generic logic in the callback.

A simple example would be as follows...

beforeSubmit: function(arr, $form, options) {
    // The array of form data takes the following form:
    // [ { name: 'username', value: 'jresig', required: true }, { name: 'password', value: 'secret', required: true } ]
    // [ { name: 'title', value: '', required: false } ]

    $.each(arr, function(index, item) {
        if(item.required && !item.value.length) {
            console.log(item.name+" is required");
        }
    });
}

It currently only applies to elements of type input (see changes in commit) but this might need to be extended or limited depending on the W3C spec.

Nick

malsup added a commit that referenced this pull request Apr 6, 2012
@malsup malsup merged commit b15b338 into jquery-form:master Apr 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants