Skip to content

Commit 85f1a72

Browse files
authored
feat: fixed tree widget on new created object (#87)
1 parent 989daa6 commit 85f1a72

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img width="1660" height="520" alt="image" src="https://github.com/user-attachments/assets/b0d5537f-29c4-46ca-b514-9862b26cb000" style="max-width: 100%; height: auto; max-height: 520px;" />
1+
<img alt="image" src="https://github.com/user-attachments/assets/b0d5537f-29c4-46ca-b514-9862b26cb000"/>
22

33
# Django SmartBase Admin
44

@@ -19,18 +19,18 @@ Built to **speed up development** of internal tools and admin panels — beautif
1919
- Beautiful modern UI (Tailwind CSS)
2020
- Responsive & mobile-friendly
2121
- End-user ready for building SaaS or similar projects with global queryset configuration
22-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/ebbcacea-9052-409e-99bb-9f9e0804bbc5" style="max-width: 100%; height: auto; max-height: 1720px;" />
23-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/8003df6a-e035-4c8f-8e90-0e710818d33e" style="max-width: 100%; height: auto; max-height: 1720px;" />
24-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/29e116de-a8c6-4f22-8485-3e0eba5ed564" style="max-width: 100%; height: auto; max-height: 1720px;" />
25-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/46aefe59-e49c-4483-ba1f-eb18397db6ae" style="max-width: 100%; height: auto; max-height: 1720px;" />
26-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/ea354dcb-b4a9-47af-8046-ba0d55d72746" style="max-width: 100%; height: auto; max-height: 1720px;" />
27-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/10a5d75c-ae3e-4e2b-aeb2-e943e6363a2f" style="max-width: 100%; height: auto; max-height: 1720px;" />
28-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/3e6bfdbb-0c07-4fad-96f0-552cbcc9d4ae" style="max-width: 100%; height: auto; max-height: 1720px;" />
29-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/b3acd00b-c425-4e5f-b113-97215bb85157" style="max-width: 100%; height: auto; max-height: 1720px;" />
30-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/dc5f3f80-3325-4f5d-acec-236d6b241a7f" style="max-width: 100%; height: auto; max-height: 1720px;" />
31-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/216d4e50-5af4-4e57-8649-1211a82f493e" style="max-width: 100%; height: auto; max-height: 1720px;" />
32-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/167461dd-ec2e-4327-a208-4014f42100f9" style="max-width: 100%; height: auto; max-height: 1720px;" />
33-
<img width="2880" height="1720" alt="image" src="https://github.com/user-attachments/assets/3871e505-1bc9-4a6c-8457-4ad363a582af" style="max-width: 100%; height: auto; max-height: 1720px;" />
22+
<img alt="image" src="https://github.com/user-attachments/assets/ebbcacea-9052-409e-99bb-9f9e0804bbc5" />
23+
<img alt="image" src="https://github.com/user-attachments/assets/8003df6a-e035-4c8f-8e90-0e710818d33e" />
24+
<img alt="image" src="https://github.com/user-attachments/assets/29e116de-a8c6-4f22-8485-3e0eba5ed564" />
25+
<img alt="image" src="https://github.com/user-attachments/assets/46aefe59-e49c-4483-ba1f-eb18397db6ae" />
26+
<img alt="image" src="https://github.com/user-attachments/assets/ea354dcb-b4a9-47af-8046-ba0d55d72746" />
27+
<img alt="image" src="https://github.com/user-attachments/assets/10a5d75c-ae3e-4e2b-aeb2-e943e6363a2f" />
28+
<img alt="image" src="https://github.com/user-attachments/assets/3e6bfdbb-0c07-4fad-96f0-552cbcc9d4ae" />
29+
<img alt="image" src="https://github.com/user-attachments/assets/b3acd00b-c425-4e5f-b113-97215bb85157" />
30+
<img alt="image" src="https://github.com/user-attachments/assets/dc5f3f80-3325-4f5d-acec-236d6b241a7f" />
31+
<img alt="image" src="https://github.com/user-attachments/assets/216d4e50-5af4-4e57-8649-1211a82f493e" />
32+
<img alt="image" src="https://github.com/user-attachments/assets/167461dd-ec2e-4327-a208-4014f42100f9" />
33+
<img alt="image" src="https://github.com/user-attachments/assets/3871e505-1bc9-4a6c-8457-4ad363a582af" />
3434

3535

3636
## 📚 Full Documentation (in progress)

src/django_smartbase_admin/static/sb_admin/src/js/tree_widget.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ const loadValue = function ($inputEl, treeWidgetData, treeInstance) {
4848
$treeEl.on('change', (e) => {
4949
const changeTarget = e.target.dataset['changeTarget']
5050
if(changeTarget) {
51-
const changeTargetEl = document.querySelector(changeTarget)
52-
if(changeTargetEl) {
53-
changeTargetEl.value = e.target.value
51+
const inlineWrapper = e.target.closest('.djn-inline-form')
52+
if (inlineWrapper) {
53+
const changeTargetEl = inlineWrapper.querySelector(changeTarget)
54+
if(changeTargetEl) {
55+
changeTargetEl.value = e.target.value
56+
}
5457
}
5558
}
5659
})
@@ -371,7 +374,7 @@ const loadValue = function ($inputEl, treeWidgetData, treeInstance) {
371374
const initAllTrees = function () {
372375
$('.js-tree-widget').each(function (index, element) {
373376
const $treeEl = $(element)
374-
if ($treeEl.hasClass('fancytree-container')) {
377+
if ($treeEl.hasClass('fancytree-container') || element.closest('.djn-empty-form')) {
375378
return
376379
}
377380
const $dropdownMenu = $treeEl.closest('.dropdown-menu')

src/django_smartbase_admin/templates/sb_admin/inlines/table_inline.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
<span>{% trans 'Add' %}</span>
4141
</a>
4242
{% else %}
43-
<a href="javascript://" class="add-handler djn-add-handler btn btn-icon ml-auto {{ inline_admin_formset.handler_classes|join:" " }}">
44-
<svg class="w-20 h-20 md:mr-8">
45-
<use xlink:href="#Plus"></use>
46-
</svg>
47-
<span>{% trans 'Add' %}</span>
48-
</a>
43+
<div class="djn-add-item ml-auto">
44+
<a href="javascript://" class="add-handler djn-add-handler btn btn-icon {{ inline_admin_formset.handler_classes|join:" " }}">
45+
<svg class="w-20 h-20 md:mr-8">
46+
<use xlink:href="#Plus"></use>
47+
</svg>
48+
<span>{% trans 'Add' %}</span>
49+
</a>
50+
</div>
4951
{% endif %}
5052
{% endif %}
5153
</div>

0 commit comments

Comments
 (0)