Tweak form handling for sending a new message, for more customization
This commit is contained in:
parent
70e5915e51
commit
051b52bd4b
4 changed files with 46 additions and 22 deletions
|
@ -3,8 +3,12 @@
|
|||
|
||||
<%def name="title()">New ${model_title}</%def>
|
||||
|
||||
<%def name="head_tags()">
|
||||
${parent.head_tags()}
|
||||
<%def name="extra_javascript()">
|
||||
${parent.extra_javascript()}
|
||||
${self.disable_button_js()}
|
||||
</%def>
|
||||
|
||||
<%def name="disable_button_js()">
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
|
|
|
@ -13,6 +13,25 @@
|
|||
% endfor
|
||||
]);
|
||||
|
||||
// validate message before sending
|
||||
function validate_message_form() {
|
||||
var form = $('#new-message');
|
||||
|
||||
if (! form.find('input[name="Message--recipients"]').val()) {
|
||||
alert("You must specify some recipient(s) for the message.");
|
||||
$('.recipients input').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;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
var recipients = $('.recipients input');
|
||||
|
@ -57,27 +76,20 @@
|
|||
|
||||
// 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>
|
||||
${self.validate_message_js()}
|
||||
</%def>
|
||||
|
||||
<%def name="validate_message_js()">
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('#new-message').submit(function() {
|
||||
return validate_message_form();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
<%def name="extra_styles()">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue