Hi.
I am dynamically adding dependants to a form with jQuery link like so:
$('a.add').live('click',function() {
// Show the next hidden table on clicking add child button
$(this).closest('form').find('table.child:hidden:first').show();
$(this).closest('form').find('hr:hidden:first').show();
// Get the number of hidden tables
var $hiddenChildren = $('table.child:hidden').length;
if ($hiddenChildren == 0) {
// If there are no more to add hide the add button
$('table.addDependant').addClass('hide');
} else if ($hiddenChildren < $childTables ) {
// Show the remove button
$('a.remove').show();
}
// set a cookie for the visible state of all child tables
$('table.child').each(function(){
var $childCount = $(this).index('table.child');
if ($(this).is(':visible')) {
$.cookies.set('tableStatus' + $childCount, 'visible');
} else {
$.cookies.set('tableStatus' + $childCount, 'hidden');
}
});
return false;
});
So i am storing the visible state of each table in a cookie using this plugin:
https://code.google.com/p/cookies/wiki/Documentation
What i cannot work out is how after a page refresh or a form submit to keep those tables that have a stored value of 'visible' visible?
Am doing something similar for one element like so:
$('div.chevron').addClass('hide');
$('a.helpChoose').live('click',function() {
$('div.chevron').toggle();
if ($('div.chevron').is(':hidden')) {
//alert('hidden');
$.cookies.set('helpChoose', 'hidden');
} else {
//alert('visible');
$.cookies.set('helpChoose', 'visible');
}
return false;
});
// get the value of the cookie
var $helpChoose = $.cookies.get('helpChoose');
// if variable not null
if ($helpChoose) {
if ($helpChoose == 'hidden') {
$('.chevron').hide();
} else if ($helpChoose == 'visible') {
$('.chevron').show();
}
}
But need to abstract/extend it to multiple elements.