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:
Lance Edgar 2016-09-13 20:23:51 -05:00
parent 378f1ae7fb
commit 94a7a15e6d
4 changed files with 26 additions and 5 deletions

View file

@ -1,6 +1,6 @@
## -*- coding: utf-8 -*-
<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}

View file

@ -59,7 +59,25 @@
// set focus to recipients field
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>
<style type="text/css">