Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h3>My Services</h3>
- {{ serviceFormset.management_form }}
- {% for form in serviceFormset.forms %}
- <div class='table'>
- <table class='no_error'>
- {{ form.as_table }}
- </table>
- </div>
- {% endfor %}
- <input type="button" value="Add More" id="add_more">
- <script>
- $('#add_more').click(function() {
- cloneMore('div.table:last', 'service');
- });
- </script>
- function cloneMore(selector, type) {
- var newElement = $(selector).clone(true);
- var total = $('#id_' + type + '-TOTAL_FORMS').val();
- newElement.find(':input').each(function() {
- var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
- var id = 'id_' + name;
- $(this).attr({'name': name, 'id': id}).val('').removeAttr('checked');
- });
- newElement.find('label').each(function() {
- var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
- $(this).attr('for', newFor);
- });
- total++;
- $('#id_' + type + '-TOTAL_FORMS').val(total);
- $(selector).after(newElement);
- }
- js = ('/media/js/jquery.js', '/media/js/admin/AddInline.js', )
- function cloneMore(selector, type) {
- var newElement = $(selector).clone(true);
- var total = $('#id_' + type + '-TOTAL_FORMS').val();
- newElement.find(':input').each(function() {
- var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
- var id = 'id_' + name;
- if ($(this).attr('type') != 'hidden') {
- $(this).val('');
- }
- $(this).attr({'name': name, 'id': id}).removeAttr('checked');
- });
- newElement.find('label').each(function() {
- var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
- $(this).attr('for', newFor);
- });
- total++;
- $('#id_' + type + '-TOTAL_FORMS').val(total);
- $(selector).after(newElement);
- }
- $('table tr.add-row a').click(function() {
- toSanitize = new Array('id', 'product', 'price', 'type', 'valid_from', 'valid_until');
- cloneMore('div.formtable table tr.form-row:last', 'form', toSanitize);
- });
- function cloneMore(selector, type, sanitize) {
- var newElement = $(selector).clone(true);
- var total = $('#id_' + type + '-TOTAL_FORMS').val();
- newElement.find(':input').each(function() {
- var namePure = $(this).attr('name').replace(type + '-' + (total-1) + '-', '');
- var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
- var id = 'id_' + name;
- $(this).attr({'name': name, 'id': id}).removeAttr('checked');
- if ($.inArray(namePure, sanitize) != -1) {
- $(this).val('');
- }
- });
- newElement.find('label').each(function() {
- var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
- $(this).attr('for', newFor);
- });
- total++;
- $('#id_' + type + '-TOTAL_FORMS').val(total);
- $(selector).after(newElement);
- }
- var newElement = $(selector).clone();
- var newElement = $(selector).clone(true);
- <h3>My Services</h3>
- {{ serviceFormset.management_form }}
- <div id="form_set">
- {% for form in serviceFormset.forms %}
- <table class='no_error'>
- {{ form.as_table }}
- </table>
- {% endfor %}
- </div>
- <input type="button" value="Add More" id="add_more">
- <div id="empty_form" style="display:none">
- <table class='no_error'>
- {{ serviceFormset.empty_form.as_table }}
- </table>
- </div>
- <script>
- $('#add_more').click(function() {
- var form_idx = $('#id_form-TOTAL_FORMS').val();
- $('#form_set').append($('#empty_form').html().replace(/__prefix__/g, form_idx));
- $('#id_form-TOTAL_FORMS').val(parseInt(form_idx) + 1);
- });
- </script>
Add Comment
Please, Sign In to add comment