diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -217,9 +217,34 @@ function resetForm(form) { form.find('input:text, input:password, input:file, select, textarea').val(''); form.find('input:radio, input:checkbox') .removeAttr('checked').removeAttr('selected'); - $('#file_wrap').find('#file-thumb').remove(); + $('.file_wrap').find('.file-thumb').remove(); } +/** + * When the form is posted, this method will be run as a callback + */ +function updateOnPost(response, statusText, xhr, form) { + var json = $.parseJSON(response); + var status = json.status; + + form.children('.form-errors').remove(); + + if (status === 'ok') { + resetForm(form); + updateThread(); + } else { + var errors = json.errors; + for (var i = 0; i < errors.length; i++) { + var fieldErrors = errors[i]; + + var error = fieldErrors.errors; + + var errorList = $('
' + error + + '
'); + errorList.appendTo(form); + } + } +} $(document).ready(function(){ initAutoupdate(); @@ -228,33 +253,13 @@ function resetForm(form) { var threadId = $('div.thread').children('.post').first().attr('id');; var form = $('#form'); + var options = { success: updateOnPost, - url: '/api/add_post/' + threadId + '/', + url: '/api/add_post/' + threadId + '/' }; form.ajaxForm(options); - function updateOnPost(response, statusText, xhr, $form) { - var json = $.parseJSON(response); - var status = json.status; - - form.children('.form-errors').remove(); - - if (status === 'ok') { - resetForm(form); - updateThread(); - } else { - var errors = json.errors; - for (var i = 0; i < errors.length; i++) { - var fieldErrors = errors[i]; - - var error = fieldErrors.errors; - - var errorList = $('
' + error - + '
'); - errorList.appendTo(form); - } - } - } + resetForm(form); });