- Author:
- I159
- Posted:
- November 16, 2011
- Language:
- JavaScript
- Version:
- Not specified
- Score:
- -1 (after 1 ratings)
If you need dynamical formsets you can use {{ empty_form }}
in template and even makeup it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | TEMPLATE_MAKEUP['language'] = '<tr>\n'+
'<td class="labels">\n'+
'<label for="">\n'+
'{{ language_form.empty_form.language|escapejs }}{{ language_form.empty_form.language.errors|escapejs }}:'+
'</label>\n'+
'</td>\n'+
'<td class="fields">\n'+
'<table cellpadding="0" cellspacing="0" border="0" class="sub_tables languages">\n'+
'{{ language_form.empty_form.level|escapejs }}{{ language_form.empty_form.level.errors|escapejs }}'+
'</table>\n'+
'</td>\n'+
'</tr>\n';
TEMPLATE_MAKEUP['education'] = '<tr class="removeble_label">\n'+
'<td class="line_break"> </td>\n'+
'</tr>\n'+
'<tr class="removeble_label">\n'+
'<td class="labels">\n'+
'<label for="">\n'+
'<b>\n'+
'Второе образование:'+
'</b>\n'+
'</label>\n'+
'</td>\n'+
'</tr>\n'+
'<tr>\n'+
'<td class="labels"><label for="">Учебное заведение:</label></td>\n'+
'<td class="fields">\n'+
'{{ education_form.empty_form.institution|escapejs }}{{ education_form.empty_form.institution.errors|escapejs }}'+
'</td>\n'+
'</tr>\n'+
'<tr>\n'+
'<td class="labels"><label for="">Факультет:</label></td>\n'+
'<td class="fields">\n'+
'{{ education_form.empty_form.faculty|escapejs }}{{ education_form.empty_form.faculty.errors|escapejs }}'+
'</td>\n'+
'</tr>\n'+
'<tr>\n'+
'<td class="labels"><label for="">Специальность:</label></td>\n'+
'<td class="fields">\n'+
'{{ education_form.empty_form.specialty|escapejs }}{{ education_form.empty_form.specialty.errors|escapejs }}'+
'</td>\n'+
'</tr>\n'+
'<tr>\n'+
'<td class="labels"><label for="">Квалификация:</label></td>\n'+
'<td class="fields">\n'+
'{{ education_form.empty_form.qualification|escapejs }}{{ education_form.empty_form.qualification.errors|escapejs }}'+
'</td>\n'+
'</tr>\n'+
'<tr>\n'+
'<td class="labels"><label for="">Год оконцания:</label></td>\n'+
'<td class="fields">\n'+
'{{ education_form.empty_form.graduation_year|escapejs }}{{ education_form.empty_form.graduation_year.errors|escapejs }}'+
'</td>\n'+
'</tr>';
/* Without deletion.*/
function addForm(form_count, form_name, temp_form){
var button = $('#' + form_name + ' .add_form_button');
button.click(function() {
var form = temp_form.replace(/__prefix__/g, form_count);
form_count++;
button.closest('tr').before(form);
$('#id_form-TOTAL_FORMS').val(form_count);
$('#id_form-MAX_NUM_FORMS').val(form_count);
});
};
/* With deletion */
function addDelEducation(){
var checked = $('.education_number:checked');
var form = TEMPLATE_MAKEUP['education'].replace(/__prefix__/g, 1);
if(checked.val() == 2){
$('#education_form').append(form);
$('#id_education-TOTAL_FORMS').val(2);
}else if(checked.val() == 1){
$('#id_education-TOTAL_FORMS').val(1);
$('.removeble_label').remove();
var inputs = $('#education_form input:text');
for(var i=0; i<inputs.length; i++){
if($(inputs[i]).attr('id').indexOf('1') != -1){
$(inputs[i]).closest('tr').remove();
};
};
};
};
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 10 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 11 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 7 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 8 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 12 years ago
Comments
Please login first before commenting.