Add basic form validation when sending new messages
This avoids the message body for now, since that's implemented a couple different ways in the real world...
This commit is contained in:
parent
378f1ae7fb
commit
94a7a15e6d
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2014 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,18 +24,20 @@
|
||||||
FormAlchemy Forms
|
FormAlchemy Forms
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.core import Object
|
from rattail.core import Object
|
||||||
|
|
||||||
from pyramid.renderers import render
|
from pyramid.renderers import render
|
||||||
from ..db import Session
|
|
||||||
|
from tailbone.db import Session
|
||||||
|
|
||||||
|
|
||||||
class AlchemyForm(Object):
|
class AlchemyForm(Object):
|
||||||
"""
|
"""
|
||||||
Form to contain a :class:`formalchemy.FieldSet` instance.
|
Form to contain a :class:`formalchemy.FieldSet` instance.
|
||||||
"""
|
"""
|
||||||
|
id = None
|
||||||
create_label = "Create"
|
create_label = "Create"
|
||||||
update_label = "Save"
|
update_label = "Save"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
## -*- coding: utf-8 -*-
|
## -*- coding: utf-8 -*-
|
||||||
<div class="form">
|
<div class="form">
|
||||||
${h.form(form.action_url, id=form_id or None, method='post', enctype='multipart/form-data')}
|
${h.form(form.action_url, id=form.id or None, method='post', enctype='multipart/form-data')}
|
||||||
|
|
||||||
${form.render_fields()|n}
|
${form.render_fields()|n}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,25 @@
|
||||||
// set focus to recipients field
|
// set focus to recipients field
|
||||||
recipients.data('ui-tagit').tagInput.focus();
|
recipients.data('ui-tagit').tagInput.focus();
|
||||||
|
|
||||||
|
// validate message before sending
|
||||||
|
$('#new-message').submit(function() {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
if (! form.find('input[name="Message--recipients"]').val()) {
|
||||||
|
alert("You must specify some recipient(s) for the message.");
|
||||||
|
recipients.data('ui-tagit').tagInput.focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! form.find('input[name="Message--subject"]').val()) {
|
||||||
|
alert("You must provide a subject for the message.");
|
||||||
|
form.find('input[name="Message--subject"]').focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,7 @@ class MessagesView(MasterView):
|
||||||
def make_form(self, instance, **kwargs):
|
def make_form(self, instance, **kwargs):
|
||||||
form = super(MessagesView, self).make_form(instance, **kwargs)
|
form = super(MessagesView, self).make_form(instance, **kwargs)
|
||||||
if self.creating:
|
if self.creating:
|
||||||
|
form.id = 'new-message'
|
||||||
form.cancel_url = self.request.get_referrer(default=self.request.route_url('messages.inbox'))
|
form.cancel_url = self.request.get_referrer(default=self.request.route_url('messages.inbox'))
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue