<commit_before>function multiformset( options ) {

    // Create some defaults, extending them with any options that were provided
    var settings = $.extend( {
        'template_selector' : '.form_template',
        'add_form_selector' : '#multiformset-add_form',
        'form_chooser_selector' : '#multiformset-form_chooser',
        'new_form_parent' : '#multiformset-new_forms',
        'template_value_attr': 'data-form-class',
        'template_text_attr': 'data-form-class'

    }, options);

    var $chooser = $(settings.form_chooser_selector);
    $(settings.template_selector).each(function(idx, el) {
        var $el = $(el);
        $chooser.append($("<option></option>")
            .attr("value", $el.attr(settings.template_value_attr))
            .text($el.attr(settings.template_text_attr)));
    });
    $(settings.add_form_selector).click(function(evt) {
        // don't submit if this input happens to be within the form
        evt.preventDefault();

        // update total form count
        var form_name = $chooser.val();
        var $total_forms = $("#id_" + form_name + "-TOTAL_FORMS");
        var qty = parseInt($total_forms.val());
        $total_forms.val(qty + 1);

        // copy the template and replace prefixes with the correct index
        var html = $("#" + form_name + "-form_template").clone().html().replace(/__prefix__/g, qty);
        $(settings.new_form_parent).append(html);
    });

}<commit_msg>Add support for a javascript callback after inserting a new form<commit_after>function multiformset( options ) {

    // Create some defaults, extending them with any options that were provided
    var settings = $.extend( {
        'template_selector' : '.form_template',
        'add_form_selector' : '#multiformset-add_form',
        'form_chooser_selector' : '#multiformset-form_chooser',
        'new_form_parent' : '#multiformset-new_forms',
        'template_value_attr': 'data-form-class',
        'template_text_attr': 'data-form-class',
        'add_form_callback': null

    }, options);

    var $chooser = $(settings.form_chooser_selector);
    $(settings.template_selector).each(function(idx, el) {
        var $el = $(el);
        $chooser.append($("<option></option>")
            .attr("value", $el.attr(settings.template_value_attr))
            .text($el.attr(settings.template_text_attr)));
    });
    $(settings.add_form_selector).click(function(evt) {
        // don't submit if this input happens to be within the form
        evt.preventDefault();

        // update total form count
        var form_name = $chooser.val();
        var $total_forms = $("#id_" + form_name + "-TOTAL_FORMS");
        var qty = parseInt($total_forms.val());
        $total_forms.val(qty + 1);

        // copy the template and replace prefixes with the correct index
        var html = $("#" + form_name + "-form_template").clone().html().replace(/__prefix__/g, qty);
        $(settings.new_form_parent).append(html);

        if (settings.add_form_callback) {
            settings.add_form_callback(html);
        }
    });

}
{'fraction_non_alphanumeric': 0.14378448555663745, 'fraction_numerical': 0.0006491398896462187, 'mean_word_length': 2.906210392902408, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1194184', 'n_tokens_mistral': 917, 'n_tokens_neox': 909, 'n_words': 191}