I'm trying to add dynamic forms to my inline formset using the steps 
mentioned in the post: Add a dynamic form to a django formset using 
javascript in a right way 
<http://stackoverflow.com/questions/21260987/add-a-dynamic-form-to-a-django-formset-using-javascript-in-a-right-way>

I have inline formsets which i'm rendering using crispy forms.

rendering code in template:

            <div>
                {{ formset.management_form|crispy }}
            </div>
            <div id="items-form-container">
            {% for form in formset.forms %}
            <div id="item-{{ forloop.counter0 }}">
                {% crispy form formset.crispy_helper %}
            </div>
            {% endfor %}                
            </div>  


empty form template is used for adding new rows:

 <script type="text/html" id="item-template">
                <div id="item-__prefix__">
                {% crispy formset.empty_form formset.crispy_helper %} 
                </div>
                </script>
                <a href="#" id="add-item-button" class="btn btn-info 
add-profile_kvp">Add profile_kvp</a>

I have a small javascript code to handle on click on the button and updating 
the html and management form:

$(document).ready(function() {
    $('.add-profile_kvp').click(function(ev) {
        ev.preventDefault();
        var count = parseInt($('#id_profile_kvp-TOTAL_FORMS').val());
        var tmplMarkup = $('#item-template').html();
        var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count);
        $('div#items-form-container').append(compiledTmpl);

        // update form count
        $('#id_profile_kvp-TOTAL_FORMS').val(count+1);

    });});

When I click the button Add profile_kvp button i'm able to update the DOM 
properly with new values and it's looks fine in browser.

Problem appears when i submit the formset then I don't see the dynamically 
added forms/row in formset in views.py and so not able to view dynamically 
added values in server side. In server side i see new rows as empty rows 
without data. I see total forms value updated but all new forms are empty.


All the dynamically added forms went as empty forms and didn't have the 
values which I entered in the browser.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4ff3595f-6eb4-4faf-a248-0d3aac8e3d4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to