I create some checkboxs with check_box_tag in a rhtml, when I check the
checkbox, I change the css class of the checkbox with javascript,
everything is fine, however, when I press on F5 to refresh my page, the
checkbox is still checked, but the css class is turned back to the
uncheck… What happens exactly when I press F5? Is the rhtml page
rebuilt??? or what, and where the checkbox information is stored (since
it has kept its checked state) in params, session or …?
I create some checkboxs with check_box_tag in a rhtml, when I check the
checkbox, I change the css class of the checkbox with javascript,
everything is fine, however, when I press on F5 to refresh my page, the
checkbox is still checked, but the css class is turned back to the
uncheck… What happens exactly when I press F5? Is the rhtml page
rebuilt??? or what, and where the checkbox information is stored (since
it has kept its checked state) in params, session or …?
Is this firefox? I’ve noticed that reloads will cause the edits to the
form you’ve made since initial load to be kept, isntead of the form
resetting itself. If that’s what you’re experiencing, then click in the
url bar and just hit return. That seems to cause it to not only reload,
but reset the form as well.
checkbox is still checked, but the css class is turned back to the
uncheck… What happens exactly when I press F5? Is the rhtml page
rebuilt??? or what, and where the checkbox information is stored (since it has kept its checked state) in params, session or …?
when you press F5 you will usually get a new petition of the page to the
server. It depends on browser cache configuration anyway. Maybe images
are not reloaded and .js by default wouldn’t either, but rails appends a
chunk of numbers to gracefully reload js without wiping the cache.
So, when the server gets the new petition it will reload the action and,
as you say, ‘rebuild’ the rhtml (assuming you are in development
environment and didn’t change the defaults).
About the client side values, such as the selected check boxes, it’s
your browser the one populating the values again after hitting F5. On
Firefox you can force a full reload with Ctrl+F5, and not sure if on IE
was Shift+F5.
good luck,
javier ramirez
–
Estamos de estreno… si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!
use some javascript. prototype has some nice functionality to get at
form elements
var checkboxes = $(‘form_id’).getInputs(‘checkbox’);
checkboxes.each(function(cb) {
if (cb.checked == true) {
// if using class attribute
Element.addClassName(cb,
‘checked_class’);
// or if using style attribute
// Element.setStyle(cb,
{‘backgroundColor’:’#FF0000’})
}
});
no, the server has no way to know you pressed ‘F5’.
as already discussed, the steps involved are:
initial page load
you check some checkboxes off, and your styles are applied
(assuming you use an onClick event)
you press F5, telling browser to request the page again
page is (re)loaded
your browser, remembering what you did in the form, repopulates the
form. NOTE: no onclick events are fired when your browser repopulates
the form.
the next step if for you to write some javascript to set the styles on
the checkboxes that have been checked by the browser. see the example
i provided to you.
i dont get why u need to do this but you can use session to store
newly checked checkboxes even if user not pressed Submit.
just make onclick event for each checkbox(javascript), that insert to
session coookie id of checkbox.
function doRemember(domID)
{
PUT small verification code to determine wheither checkbox are
checked or not
if checked call Set_Cookie(“checkbox_” + domID, 1);
if unchecked call Set_Cookie(“checkbox_” + domID, 0);
}
function Set_Cookie(name,value)
{
var cookieString = name + "=" +escape(value);
document.cookie = cookieString;
}
<--------------------->
okay, now when u reload page and running in loop of some model just
check session cookie with “checkbox_?” names,
split it by "" and if somemodel.id = ? (of checkbox, and checkbox? =
then html attribute of this will be checked=“checked”
Make something that will make hash of all cookie checkboxes like:
checkboxes … [id, value] [id, value]
values will be 0 or 1
and id will be value after checkbox_?
Offcourse you should run another loop inside instance loop, to check
all checkbox_? cookies.
box.each do | box |
attrib = “”
checkboxes.each do | checkbox |
attrib = “checked=”
if checkbox.id == box.id
checkbox.value == 1 ? attrib += “‘checked’” : attrib +=
“‘none’”
end
end
end
Thats all for now, maybe i made somewhere mistake, didnt checked it,
but it should work.