-1

When I go to edit page all my checkboxes are checked, while when I look in the html I have some of then set to false :

<input checked="false" class="hidden" id="cover_inspiration_image_ids" name="cover[inspiration_image_ids][]" type="checkbox" value="68">

I can't understand why the checked value are not working. I also tried with checked="checked"

I tried with jquery : $(".hidden").prop('checked') and it return true

This is my code :

covers/_form

 - @inspiration_images.each do |img|
   - next if img.image.path.nil?
     .w-col.w-col-2.w-col-small-4.w-col-tiny-6
       label
         INPUT[type="checkbox" name="cover[inspiration_image_ids][]" id='cover_inspiration_image_ids' value="#{img.id}" class="hidden" checked="#{check_status(img, @cover)}"]
          .image-cov-pick
            = cl_image_tag(img.image.path, height: 190, class: 'img-to-pick').html_safe
           .white

cover_helper

module CoversHelper
  def check_status(image, cover)
    cover.inspiration_image_ids && cover.inspiration_image_ids.include?(image.id)
  end
end
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
Orsay
  • 1,080
  • 2
  • 12
  • 32

2 Answers2

1

Can you please try passing the value as Boolean instead of String

checked="#{check_status(img, @cover)}"
#to
checked=check_status(img, @cover)

full code

INPUT[type="checkbox" name="cover[inspiration_image_ids][]" id='cover_inspiration_image_ids' value="#{img.id}" class="hidden" checked=check_status(img, @cover)]
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88
0

If you don't want checkbox to be checked, don't render its checked attribute at all, with any value.

Related: What values for checked and selected are false?

Community
  • 1
  • 1
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367