diff --git a/app/assets/javascripts/character_count.js b/app/assets/javascripts/character_count.js index 2c4bcf190..a0f856ea6 100644 --- a/app/assets/javascripts/character_count.js +++ b/app/assets/javascripts/character_count.js @@ -58,7 +58,8 @@ $(() => { $(document).on('keyup change paste', '[data-character-count]', (ev) => { const $tgt = $(ev.target); const $counter = $($tgt.attr('data-character-count')); - const $button = $counter.parents('form').find('input[type="submit"],.js-suggested-edit-approve'); + const $form = $counter.parents('form'); + const $button = $form.find('input[type="submit"],.js-suggested-edit-approve'); const $count = $counter.find('.js-character-count__count'); const $icon = $counter.find('.js-character-count__icon'); @@ -76,19 +77,24 @@ $(() => { if (gtnMax || ltnMin) { setCounterState($counter, 'error'); setCounterIcon($icon, 'fa-times'); - setSubmitButtonDisabledState($button, 'disabled'); setInputValidationState($tgt, 'invalid'); } else if (gteThreshold) { setCounterState($counter, 'warning'); setCounterIcon($icon, 'fa-exclamation-circle'); - setSubmitButtonDisabledState($button, 'enabled'); } else { setCounterState($counter, 'default'); setCounterIcon($icon, 'fa-check'); - setSubmitButtonDisabledState($button, 'enabled'); setInputValidationState($tgt, 'valid'); } + const submittable = $form[0]?.checkValidity() ?? false; + + if (!submittable || gtnMax || ltnMin) { + setSubmitButtonDisabledState($button, 'disabled'); + } else { + setSubmitButtonDisabledState($button, 'enabled'); + } + $count.text(text); }); diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index de2bfede1..9e2e4131b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -32,8 +32,15 @@ def create_thread pings = check_for_pings @comment_thread, body success = ActiveRecord::Base.transaction do - @comment_thread.save! - @comment.save! + thread_success = @comment_thread.save + comment_success = @comment.save + full_success = thread_success && comment_success + + unless full_success + raise ActiveRecord::Rollback + end + + full_success end if success diff --git a/app/views/comments/_new_thread_modal.html.erb b/app/views/comments/_new_thread_modal.html.erb index 8ea24575f..360a81148 100644 --- a/app/views/comments/_new_thread_modal.html.erb +++ b/app/views/comments/_new_thread_modal.html.erb @@ -2,6 +2,12 @@ Start new comment thread dialog. %> +<% + # TODO: make configurable + min_chars = 15 + max_chars = 1000 +%> +