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

.garlic('destroy') doesn't work from success page #94

Open
nickwelsh1 opened this issue Sep 8, 2016 · 0 comments
Open

.garlic('destroy') doesn't work from success page #94

nickwelsh1 opened this issue Sep 8, 2016 · 0 comments

Comments

@nickwelsh1
Copy link

Garlic.js is awesome, however I found a limitation -

When a user fills out a form successfully they are taken to a success page
from there my code tries to destroy the local storage data
$('#form').garlic('destroy');
however the form data remains in local storage.

I think because the server has changed the page the reference to garlic's local storage key's are no longer matching.

My work-around is a little messy but this is what i used

function destroyGarlic() {
var aGarlicKeys = [];
for ( var i = 0, len = localStorage.length; i < len; ++i ) {
if ( localStorage.key(i).indexOf("garlic") >= 0 ) {
aGarlicKeys.push( localStorage.key(i) );
}
};
jQuery.each(aGarlicKeys, function(index, item) {
localStorage.removeItem(item);
});
}
destroyGarlic();
console.log('data destroyed.');

Bassically I search for all keys in local storage containing the string "garlic", push them into an array and then use the array to remove the garlic keys from local storage.

It would be great if garlic.destroy(); could be flexible like this.

Hope this helps someone

Cheers,
Nick

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

No branches or pull requests

1 participant