Page 1 of 2
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 3:24 pm
by Kevin
How do I make a button disabled for users not logged into the app?
I'm using ParseDB and when a user logs in, the sessiontoken is stored as a local storage variable.
I need a way to check if the local storage variable is empty, the button to be disable but if there is a value the button becomes enabled.
Please help.
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 3:31 pm
by maxkatz
On page load, check if the local storage variable is set, then use jQuery to select the button and disable it:
code
Tiggzi('button_name').attr('disabled', 'disabled');
/code
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 3:36 pm
by Kevin
Please Check if this code is ok
precode
var session = localStorage.getItem('sessionToken');
if (session ==''){
Tiggzi('savebutton').attr('disabled', 'disabled');
}
else {
Tiggzi('savebutton').attr('enabled', 'enabled');
}
/code/pre
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 3:44 pm
by Kevin
Actually I tried it but it doesn't work. Any advice?
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 3:47 pm
by Emmz
maybe var session null if never set.
try if (session =='' || session == null ){
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 3:53 pm
by Kevin
Thanks Neil. Still not working the button remains enabled.
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 4:15 pm
by Emmz
Sorry. Didnt notice ur attrib.
Do this ..
code
var button = Tiggzi('savebutton');
button.addClass('ui-disabled');//To Disable
button.removeClass('ui-disabled');//To enable
/code
Not sure if u need refresh.. if so use
button.removeClass('ui-disabled').refresh();//To enable
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 5:15 pm
by Kevin
Thanks tried that too. Still not working as expected.
Make a button disabled / not visible for users not logged in
Posted: Thu Oct 18, 2012 8:04 pm
by maxkatz
Add this at the end:
button.button('refresh');
http://jquerymobile.com/demos/1.2.0/d...
Make a button disabled / not visible for users not logged in
Posted: Fri Oct 19, 2012 4:10 pm
by Kevin
Hey Max thanx for the link actually I've figured out why it wasn't working.
The methods only apply to form buttons.
The button I was talking about was on the header and navbar.
Any idea how I can make this work?