Skip to content

Commit ed00a41

Browse files
committed
fix(model): display subform when model is already selected on page reload
1 parent 5b17f27 commit ed00a41

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

templates/clientinjection.html.twig

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,33 @@
6868
</div>
6969
</div>
7070

71-
{% if models_id %}
72-
<div class="row mt-3">
73-
<div class="col-12">
74-
{% if step == upload_step %}
75-
<script>
76-
Ajax.updateItem("span_injection", "{{ upload_url }}", {{ params|json_encode|raw }});
77-
</script>
78-
{% elseif step == result_step %}
79-
<script>
80-
Ajax.updateItem("span_injection", "{{ result_url }}", {{ params|json_encode|raw }});
81-
</script>
82-
{% endif %}
83-
</div>
84-
</div>
85-
{% endif %}
71+
<script>
72+
$(function() {
73+
const rand = '{{ rand }}';
74+
const uploadUrl = "{{ upload_url }}";
75+
const resultUrl = "{{ result_url }}";
76+
const modelId = {{ models_id }};
77+
const step = {{ step }};
78+
const resultStep = {{ result_step }};
79+
80+
function loadFormForModel(modelId) {
81+
if (modelId > 0) {
82+
const url = (step === resultStep) ? resultUrl : uploadUrl;
83+
$('#span_injection').load(url, { models_id: modelId });
84+
}
85+
}
86+
87+
// On model change
88+
$('#clientinjection_form' + rand + ' select[name="dropdown_models"]').on('change select2:select', function() {
89+
loadFormForModel($(this).val());
90+
});
91+
92+
// Initial load
93+
if (modelId > 0) {
94+
loadFormForModel(modelId);
95+
}
96+
});
97+
</script>
8698
</div>
8799
</form>
88100
</div>

0 commit comments

Comments
 (0)