Skip to content

Commit

Permalink
Fix clear input on form reset, fix #110
Browse files Browse the repository at this point in the history
  • Loading branch information
monim67 committed Feb 11, 2024
1 parent e85b6a2 commit a3be637
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap3/custom-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
{% endbuttons %}
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap3/custom-formset.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{% endfor %}
{% buttons %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
{% endbuttons %}
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap3/modal-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h3>{{ title_text }}</h3>
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
{% endbuttons %}
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap4/custom-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h2 class="pb-2 mt-4 mb-2 border-bottom">Custom Form with Bootstrap 4</h2>
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
{% endbuttons %}
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap4/custom-formset.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h2 class="pb-2 mt-4 mb-2 border-bottom">Custom Form with Bootstrap 4</h2>
{% endfor %}
{% buttons %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
{% endbuttons %}
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap4/modal-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h2 class="pb-2 mt-4 mb-2 border-bottom">Custom Form with Bootstrap 4</h2>
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
{% endbuttons %}
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap5/custom-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h2 class="pb-2 mt-4 mb-2 border-bottom">Custom Form with Bootstrap 5</h2>
{% csrf_token %}
{% bootstrap_form form %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
</form>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap5/custom-formset.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h2 class="pb-2 mt-4 mb-2 border-bottom">Custom Form with Bootstrap 5</h2>
{% endfor %}
<div class="mt-2">
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
</div>
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions dev/myapp/templates/myapp/bootstrap5/modal-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h2 class="pb-2 mt-4 mb-2 border-bottom">{{ title_text }}</h2>
{% bootstrap_form form %}
{% bootstrap_alert "Demo site is static HTML clone of django, submitting won't work" alert_type='warning' %}
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
<button type="reset" class="btn btn-warning">Reset</button>
</form>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
const widgetInstance = createWidgetInstance(inputWrapper, hiddenInputElement, config);
widgetInstances.set(hiddenInputElement, widgetInstance);

const form = hiddenInputElement.closest("form");
form?.addEventListener("reset", () => {
setTimeout(() => inputElement.dispatchEvent(new Event("change")));
})

if (config.range_from) {
const widgetRangeFromInstance = getRangeFromInputElement(hiddenInputElement, config);
if (widgetRangeFromInstance) {
Expand Down

0 comments on commit a3be637

Please sign in to comment.