开发者

Django admin clear button for form

开发者 https://www.devze.com 2022-12-29 19:37 出处:网络
I开发者_如何学C was wondering if there is a way to put a \"Clear Form\" button on the admin forms of the apps in django? In your templates directory create a folder admin, in this create a file submit

I开发者_如何学C was wondering if there is a way to put a "Clear Form" button on the admin forms of the apps in django?


In your templates directory create a folder admin, in this create a file submit_line.html, paste this code in there (this is actually the original submit_line with the last <input... statement added:

{% load i18n %}
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{% endif %}>
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" {{ onclick_attrib }}/>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" {{ onclick_attrib }}/>{%endif%}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" {{ onclick_attrib }} />{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" {{ onclick_attrib }}/>{% endif %}
<input type="reset" value="Reset form" />
</div>

Now, while this will do what you want, the Reset Form button will appear not to be clickable in some browsers (some effect is disabled). It will however work. You can also replace the input by <button type="reset">Reset form</button> but I find this rather ugly. Finally, you could also search the stylesheets to see which code fails (it's something like a input['reset'] that's missing somewhere). But anyway, this works, have fun with it

0

精彩评论

暂无评论...
验证码 换一张
取 消