-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to ensure added forms can be deleted
For `<template>` elements, the `template.content` property returns a DocumentFragment instead of a Node. These can be added easily to the DOM using `appendChild`, but deleting them using `removeChild` is non-trivial in such cases, as pointed out it #6. To overcome this problem, the `template.content.firstElementChild` is added to the DOM instead, which is a Node. This does require the template element to contain only a single element and the library now also checks for this upon initialization, but in practice this was already the case. End-to-end tests are updated to assert this check is performed and to ensure added forms can indeed be deleted. The documentation is updated to clarify that each form should be contained inside a single parent element denoted by the `formSelector` parameter.
- Loading branch information
Showing
5 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
py_tests/django_test_project/templates/initialization/malformed_empty_form_template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% extends "base.html" %} | ||
|
||
|
||
{% block page_scripts %} | ||
<script> | ||
window.addEventListener('load', function(event) { | ||
new ConvenientFormset({ | ||
'formsetPrefix': 'formset', | ||
'formsContainerSelector': '#formset #forms-container', | ||
'formSelector': '.form', | ||
|
||
'canAddForms': true, | ||
'addFormButtonSelector': '#formset #add-form-button', | ||
'emptyFormTemplateSelector': '#formset #empty-form-template', | ||
'hideAddFormButtonOnMaxForms': true, | ||
|
||
'canDeleteForms': false, | ||
|
||
'canOrderForms': false, | ||
}); | ||
}); | ||
</script> | ||
{% endblock%} | ||
|
||
|
||
{% block page_contents %} | ||
<div id="formset"> | ||
<div id="forms-container"></div> | ||
<input type="button" id="add-form-button" value="Add form"> | ||
<template id="empty-form-template"> | ||
<div class="form"> | ||
<input type="text" name="formset-__prefix__-user" value=""> | ||
</div> | ||
<div class="another-form"> | ||
<input type="text" name="formset-__prefix__-user" value=""> | ||
</div> | ||
</template> | ||
<div id="management-form"> | ||
<input type="hidden" name="formset-TOTAL_FORMS" value="0"> | ||
<input type="hidden" name="formset-INITIAL_FORMS" value="0"> | ||
<input type="hidden" name="formset-MIN_NUM_FORMS" value="0"> | ||
<input type="hidden" name="formset-MAX_NUM_FORMS" value="5"> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters