Hide extra maintainer forms and show each one on request

Hide all empty maintainer forms and have a button to "add" another
maintainer which just uses jQuery to show the next hidden form. Up to
10 maintainers can be added which should be more than enough.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2013-02-27 23:53:37 +00:00
parent 9a3bfac320
commit 0e14cf17d8
3 changed files with 29 additions and 8 deletions

View File

@ -73,6 +73,7 @@
{{ maintainerformset.non_form_errors }}
{{ maintainerformset.management_form }}
{% for maintainerform in maintainerformset %}
<div class="maintainerform" id="maintainerform-{{forloop.counter0}}">
<h4>Maintainer {{forloop.counter}}</h4>
{% for hidden in maintainerform.hidden_fields %}
{{ hidden }}
@ -86,9 +87,11 @@
{{ field.help_text }}
</div>
{% endfor %}
</div>
{% endfor %}
<p><a href="#" class="btn" id="addanothermaintainer">Add another maintainer</a><p>
{% block submitbuttons %}
<input type="submit" value="Save" class='btn' />
<input type="submit" value="Save" class="btn btn-primary" />
{% endblock %}
</form>
@ -165,14 +168,32 @@
}
}
for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
name_input = $('#id_layermaintainer_set-' + i + '-name')
name_input.change(split_email)
resp_id = 'id_layermaintainer_set-' + i + '-responsibility'
window['last_' + resp_id] = ""
expand_maintainer = function() {
for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
maintbox = $('#maintainerform-' + i)
if( maintbox.is(':hidden') ) {
maintbox.slideToggle();
if( i == {{maintainerformset.total_form_count}} - 1 )
$('#addanothermaintainer').hide()
break
}
}
return false;
}
$(document).ready(function() {
$('.maintainerform').hide()
for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
name_input = $('#id_layermaintainer_set-' + i + '-name')
name_input.change(split_email)
resp_id = 'id_layermaintainer_set-' + i + '-responsibility'
window['last_' + resp_id] = ""
if( i==0 || name_input.val() )
$('#maintainerform-' + i).show()
}
$('#addanothermaintainer').click(expand_maintainer)
$('#id_vcs_url').change(auto_web_fields)
});
</script>

View File

@ -41,7 +41,7 @@ class BaseLayerMaintainerFormSet(forms.models.BaseInlineFormSet):
f.required = True
return f
LayerMaintainerFormSet = inlineformset_factory(LayerItem, LayerMaintainer, form=LayerMaintainerForm, formset=BaseLayerMaintainerFormSet, can_delete=False)
LayerMaintainerFormSet = inlineformset_factory(LayerItem, LayerMaintainer, form=LayerMaintainerForm, formset=BaseLayerMaintainerFormSet, can_delete=False, extra=10, max_num=10)
class SubmitLayerForm(forms.ModelForm):
# Additional form fields

View File

@ -25,5 +25,5 @@
{% endblock %}
{% block submitbuttons %}
<input type="submit" value="Submit" class='btn' />
<input type="submit" value="Submit" class="btn btn-primary" />
{% endblock %}