fix: add action_method
and reset_url
params for Form class
so a form can use GET instead of POST, and reset button can be a link. these are needed for new report views
This commit is contained in:
parent
b972f1a132
commit
ffd4ee929c
|
@ -161,10 +161,23 @@ class Form:
|
|||
|
||||
See also :meth:`set_required()` and :meth:`is_required()`.
|
||||
|
||||
.. attribute:: action_method
|
||||
|
||||
HTTP method to use when submitting form; ``'post'`` is default.
|
||||
|
||||
.. attribute:: action_url
|
||||
|
||||
String URL to which the form should be submitted, if applicable.
|
||||
|
||||
.. attribute:: reset_url
|
||||
|
||||
String URL to which the reset button should "always" redirect,
|
||||
if applicable.
|
||||
|
||||
This is null by default, in which case it will use standard
|
||||
browser behavior for the form reset button (if shown). See
|
||||
also :attr:`show_button_reset`.
|
||||
|
||||
.. attribute:: cancel_url
|
||||
|
||||
String URL to which the Cancel button should "always" redirect,
|
||||
|
@ -227,6 +240,9 @@ class Form:
|
|||
Flag indicating whether a Reset button should be shown.
|
||||
Default is ``False``.
|
||||
|
||||
Unless there is a :attr:`reset_url`, the reset button will use
|
||||
standard behavior per the browser.
|
||||
|
||||
.. attribute:: show_button_cancel
|
||||
|
||||
Flag indicating whether a Cancel button should be shown.
|
||||
|
@ -266,7 +282,9 @@ class Form:
|
|||
readonly_fields=[],
|
||||
required_fields={},
|
||||
labels={},
|
||||
action_method='post',
|
||||
action_url=None,
|
||||
reset_url=None,
|
||||
cancel_url=None,
|
||||
cancel_url_fallback=None,
|
||||
vue_tagname='wutta-form',
|
||||
|
@ -290,9 +308,11 @@ class Form:
|
|||
self.readonly_fields = set(readonly_fields or [])
|
||||
self.required_fields = required_fields or {}
|
||||
self.labels = labels or {}
|
||||
self.action_method = action_method
|
||||
self.action_url = action_url
|
||||
self.cancel_url = cancel_url
|
||||
self.cancel_url_fallback = cancel_url_fallback
|
||||
self.reset_url = reset_url
|
||||
self.vue_tagname = vue_tagname
|
||||
self.align_buttons_right = align_buttons_right
|
||||
self.auto_disable_submit = auto_disable_submit
|
||||
|
@ -940,10 +960,15 @@ class Form:
|
|||
"""
|
||||
context['form'] = self
|
||||
context['dform'] = self.get_deform()
|
||||
context.setdefault('form_attrs', {})
|
||||
context.setdefault('request', self.request)
|
||||
context['model_data'] = self.get_vue_model_data()
|
||||
|
||||
# set form method, enctype
|
||||
context.setdefault('form_attrs', {})
|
||||
context['form_attrs'].setdefault('method', self.action_method)
|
||||
if self.action_method == 'post':
|
||||
context['form_attrs'].setdefault('enctype', 'multipart/form-data')
|
||||
|
||||
# auto disable button on submit
|
||||
if self.auto_disable_submit:
|
||||
context['form_attrs']['@submit'] = 'formSubmitting = true'
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
|
||||
<script type="text/x-template" id="${form.vue_tagname}-template">
|
||||
${h.form(form.action_url, method='post', enctype='multipart/form-data', **form_attrs)}
|
||||
${h.form(form.action_url, **form_attrs)}
|
||||
% if form.action_method == 'post':
|
||||
${h.csrf_token(request)}
|
||||
% endif
|
||||
|
||||
% if form.has_global_errors():
|
||||
% for msg in form.get_global_errors():
|
||||
|
@ -33,7 +35,13 @@
|
|||
% endif
|
||||
|
||||
% if form.show_button_reset:
|
||||
<b-button native-type="reset">
|
||||
<b-button
|
||||
% if form.reset_url:
|
||||
tag="a" href="${form.reset_url}"
|
||||
% else:
|
||||
native-type="reset"
|
||||
% endif
|
||||
>
|
||||
Reset
|
||||
</b-button>
|
||||
% endif
|
||||
|
|
Loading…
Reference in a new issue