Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from 3.0.3 -> 3.1.0 broke our checkbox inputs #1243

Closed
nickmalcolm opened this issue Apr 17, 2015 · 3 comments
Closed

Upgrading from 3.0.3 -> 3.1.0 broke our checkbox inputs #1243

nickmalcolm opened this issue Apr 17, 2015 · 3 comments

Comments

@nickmalcolm
Copy link

We use simple_form and the bitmask_attributes gem to let users save their email preferences.

In 3.0.3, checkboxes are checked as expected. You can check & uncheck options, and have them saved properly. After upgrading the simple_form gem to 3.1.0, checkboxes which should be checked aren't. (Flicking between the versions makes the bug appear and disappear, so I'm fairly sure it's something here).

I can't see anything in the CHANGELOG deprecations to indicate anything that might have changed? Perhaps we've always been doing it wrong, and it's only just become an issue?

I'm not sure the best place to start debugging this, but hopefully we can figure this out.

The model

class Customer < ActiveRecord::Base
  ...
  bitmask :email_preferences, :as => [:weekly_digest, :daily_digest, etc]
end

The form

  <%= simple_form_for current_customer do |f| %>
    <div class="form-inputs">
      <%= f.input :email_preferences, as: :check_boxes, collection: Customer.values_for_email_preferences, label: " " %>
    </div>

    <div class="form-actions">
      <%= f.button :submit, "Save Notifications" %>
    </div>
  <% end %>
@nickmalcolm
Copy link
Author

If it helps, here's how the HTML changes. Aside from losing checked="checked", looks like class="checkbox" has moved into a new wrapping span.

Old

<div class="form-inputs">
  <div class="input check_boxes optional customer_email_preferences">
    <label>
      <label class="checkbox">
        <input checked="checked" class="check_boxes optional" id="customer_email_preferences_weekly_digest" name="customer[email_preferences][]" type="checkbox" value="weekly_digest">
        Weekly Digest
      </label>
      <label class="checkbox">
        <input class="check_boxes optional" id="customer_email_preferences_daily_digest" name="customer[email_preferences][]" type="checkbox" value="daily_digest">
        Daily Digest
      </label>
      <input name="customer[email_preferences][]" type="hidden" value="">
    </label>
  </div>
</div>

New

<div class="form-inputs">
  <div class="input check_boxes optional customer_email_preferences">
    <label>
      <span class="checkbox">
        <label for="customer_email_preferences_weekly_digest">
          <input class="check_boxes optional" id="customer_email_preferences_weekly_digest" name="customer[email_preferences][]" type="checkbox" value="weekly_digest">
          Weekly Digest
        </label>
      </span>
      <span class="checkbox">
        <label for="customer_email_preferences_daily_digest">
          <input class="check_boxes optional" id="customer_email_preferences_daily_digest" name="customer[email_preferences][]" type="checkbox" value="daily_digest">
          Daily Digest
        </label>
      </span>
      <input name="customer[email_preferences][]" type="hidden" value="">
    </label>
  </div>
</div>

@rafaelfranca
Copy link
Collaborator

Can you please provide a sample application that reproduces the error?

@nickmalcolm
Copy link
Author

Hey Rafael,

Short answer: nope, which is embarrassing! Pretty sure it's to do with this: #828

Using value_method: :to_sym "fixes" the problem, but I'll need to figure out the actual cause. For now I'll just stick with 3.0.3. I'll reopen this if I can get a sample app going.

Sorry for the bother - hopefully this helps other people experiencing the same issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants