twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.55k stars 78.85k forks source link

Bootstrap checkbox buttons hidden status after page refresh #13875

Closed ghost closed 10 years ago

ghost commented 10 years ago

I have a form with checkbox toggle buttons (using twitter bootstrap and Rails)

<div class="btn-group" data-toggle="buttons">
  <label class="btn btn-primary">
    <input type="checkbox"> Option 1
  </label>
  <label class="btn btn-primary">
    <input type="checkbox"> Option 2
  </label>
</div>

I click and choose Option 1. Then I refresh the page. When the page is refreshed all the buttons are reset and Option 1 is not selected any more. However if I go ahead and submit the form, Option 1 is sent to the server as if it was selected (checked). Is this a bug? Is this because of something in cookie. If yes, how can I check the cookie and find the ones that should be pressed and the command to change their status to pressed.

I have text fields (<input type='text'>) in the form also. If I write in the text fields and refresh the page, the texts stay. It seems somewhere behind the scenes the state of the buttons stay as checked, too, but on the display I see them as un-checked. Therefore although the checkbox buttons seem to be un-checked when I submit the form they get submitted as checked.

Thanks a lot.

hnrch02 commented 10 years ago

Are you using Firefox?

hnrch02 commented 10 years ago

If that is the case, this is documented:

Cross-browser compatibility

Firefox persists the disabled state across page loads. A workaround for this is to use autocomplete="off".

cvrebert commented 10 years ago

Although that only mentions disabledness, not checkedness.

hnrch02 commented 10 years ago

Yeah, just saw that. Testing out if it is also the case with checkedness.

hnrch02 commented 10 years ago

Yes, that is the case. Maybe we should move that callout and change the copy.

cvrebert commented 10 years ago

Should also test Chrome just to verify that this is the Firefox-specific problem.

hnrch02 commented 10 years ago

Chrome (That is Chrome, FYI)

mdo commented 10 years ago

So we need to update that callout?

hnrch02 commented 10 years ago

Yes, because Firefox persists pretty much any form state across page loads, not only disabledness.

ghost commented 10 years ago

Thank you very much for your responses. Yes, I am using Firefox. Let me read the link you sent and see if it works for me. Really appreciate it.

ghost commented 10 years ago

Following worked for me. It resets the buttons after page refresh:

$(document).ready('bootstrap_buttons', function() {
  $('.btn').button('reset');
});
mdo commented 10 years ago

Docs change made, called out all form control states.

cvrebert commented 10 years ago

@mdo Perhaps we should consider actually using autocomplete="off" in those examples?

cvrebert commented 10 years ago

X-Ref: #793