<commit_before>jQuery(document).ready(function($) {

    $.validator.addMethod("alphanumeric", function(value, element) {
        return this.optional(element) || /^[a-z0-9]+$/i.test(value);
    }, "This field must contain only letters and numbers.");

    var form = $("form").on("submit", function() {
        // While rules are loading, make sure form is not submittable.
        return false;
    });

    $.get("rules.json", {}, "json")
        .done(function(rules) {
            var validator = form.validate({ rules: rules });

            // Remove previous submit handler that blocked submission.
            form.off("submit");

            form.on("submit", function() {
                var skip = form.find("#skip_client_validation").is(":checked");
                if (skip || validator.form()) {
                    // Disable the submit button while posting.
                    var submit = form.find(":submit").attr("disabled", "disabled");
                    $.post(form.attr("action") || "", form.serialize(), "json")
                        .done(function(response) {
                            if (response.successful) {
                                alert("Form submission was successful.")
                            } else {
                                alert("Form submission has failed.")
                            }
                        })
                        .fail(function() {
                            alert("Failed to communicate with server.");
                        })
                        .always(function() {
                            // Enable the submit button after posting.
                            submit.removeAttr("disabled");
                        });
                }
                return false;
            });
        });

});<commit_msg>Updated form.js to use the submitHandler argument of the jQuery Validation plugin.<commit_after>jQuery(document).ready(function($) {

    $.validator.addMethod("alphanumeric", function(value, element) {
        return this.optional(element) || /^[a-z0-9]+$/i.test(value);
    }, "This field must contain only letters and numbers.");

    var form = $("form").on("submit", function() {
        // While rules are loading, make sure form is not submittable.
        return false;
    });

    $.get("rules.json", {}, "json")
        .done(function(rules) {
            // Remove previous submit handler that blocked submission.
            form.off("submit");

            var validator = form.validate({
                rules: rules,
                submitHandler: function() {
                    var skip = form.find("#skip_client_validation").is(":checked");
                    if (skip || validator.form()) {
                        // Disable the submit button while posting.
                        var submit = form.find(":submit").attr("disabled", "disabled");
                        $.post(form.attr("action") || "", form.serialize(), "json")
                            .done(function(response) {
                                if (response.successful) {
                                    alert("Form submission was successful.")
                                } else {
                                    alert("Form submission has failed.")
                                }
                            })
                            .fail(function() {
                                alert("Failed to communicate with server.");
                            })
                            .always(function() {
                                // Enable the submit button after posting.
                                submit.removeAttr("disabled");
                            });
                    }
                    return false;
                }
            });
        });

});
{'fraction_non_alphanumeric': 0.12375719518576661, 'fraction_numerical': 0.0010465724751439038, 'mean_word_length': 1.202188940092166, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6638256', 'n_tokens_mistral': 850, 'n_tokens_neox': 808, 'n_words': 203}