Plots2: Publish button should be disabled if the comment is empty

Created on 28 Feb 2020  路  7Comments  路  Source: publiclab/plots2

Please describe the problem (or idea)

Current behavior shows the publish button as enabled when the comment is empty.This needs to be modified to enable the publish button only with comments with some text.
image9

Please show us where to look

/questions

Thank you!

bug

All 7 comments

@VladimirMikulic @jywarren can you kindly approve? Thanks :v:

@Tlazypanda :+1:

I would like to work on this bug with @mekeenan1

@mekeenan1 and I are having some trouble trying to isolate this issue. We have found the publish button for comments posts in the path app/views/comments/_form.html.erb line 107.

      <button type="submit" class="btn btn-primary" ><%= translation('comments._form.publish') %></button>

       <% if local_assigns[:comment] %> 

          <a class="btn btn-outline-secondary preview-btn" onClick="$('#c<%= comment.cid %>preview').toggle();

              $('#c<%= comment.cid %>text-input').toggle();

              $('#c<%= comment.cid %>edit .preview-btn').button('toggle');

              $E.generate_preview('c<%= comment.cid %>preview',$('#c<%= comment.cid %>text-input').val())">

            <%= translation('comments._form.preview') %>

          </a>

We can see that when there is no text in the text box, and you click publish, it sends a request and rolls it back but we would like to disable the button (gray out and unclickable) when there is no text. When we add 'disabled' to the button class, it is permanently disabled and we are not sure how to add a jQuery event to toggle this disabled state for the button.

Hi, so i believe there is a $('button.publish').toggleClass('disabled'); method in jQuery! Just be careful for situations where there are many different buttons - like more than one comment that can be edited, response-to-comment boxes, etc -- there are a lot of Publish buttons possible on a given page, so testing this thoroughly will be really important.

Thanks, i hope this helps!

I would even encourage a system test to be extra sure other Publish buttons are not affected. Take a look at these tests to see how we do system testing!

https://github.com/publiclab/plots2/blob/f7908c321b7aa52548c33021c41b410b95390ae5/test/system/comment_test.rb#L50-L63

Thank you so much for the reply! We think we have found a way to disable the publish comment button, and toggle the disable property of the button with a script, but the script is not running and we are not sure why? We are also confused about how to access the form text box, we think it has the id "text-input", but we haven't been able to access that, or get our event listener to work.

We think the button for publishing comments is this one in plots2/app/views/comments/_form.html.erb:
Screen Shot 2020-04-21 at 11 14 22 PM

When we added the disabled property to the button, it did show up as disabled/unclickable on the page.
Screen Shot 2020-04-21 at 11 17 05 PM
Screen Shot 2020-04-21 at 11 28 34 PM

Then we added this script, so that when there is text in the comment text box, the disabled property would be removed, however, the script doesn't execute at all. We put a few alerts inside to see if they popped up, and they did not.
Screen Shot 2020-04-21 at 11 10 47 PM

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keshavsethi picture keshavsethi  路  3Comments

ebarry picture ebarry  路  3Comments

first-timers[bot] picture first-timers[bot]  路  3Comments

jywarren picture jywarren  路  3Comments

noi5e picture noi5e  路  3Comments