diff --git a/src/wuttaweb/forms/base.py b/src/wuttaweb/forms/base.py index f2b9e2c..c9567bc 100644 --- a/src/wuttaweb/forms/base.py +++ b/src/wuttaweb/forms/base.py @@ -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' diff --git a/src/wuttaweb/templates/forms/vue_template.mako b/src/wuttaweb/templates/forms/vue_template.mako index d913054..d039b76 100644 --- a/src/wuttaweb/templates/forms/vue_template.mako +++ b/src/wuttaweb/templates/forms/vue_template.mako @@ -1,8 +1,10 @@ ## -*- coding: utf-8; -*-