Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Make a button disabled / not visible for users not logged in

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Make a button disabled / not visible for users not logged in

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

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Make a button disabled / not visible for users not logged in

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

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Make a button disabled / not visible for users not logged in

Actually I tried it but it doesn't work. Any advice?

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Make a button disabled / not visible for users not logged in

maybe var session null if never set.
try if (session =='' || session == null ){

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Make a button disabled / not visible for users not logged in

Thanks Neil. Still not working the button remains enabled.

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Make a button disabled / not visible for users not logged in

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

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Make a button disabled / not visible for users not logged in

Thanks tried that too. Still not working as expected.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Make a button disabled / not visible for users not logged in

Add this at the end:
button.button('refresh');

http://jquerymobile.com/demos/1.2.0/d...

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Make a button disabled / not visible for users not logged in

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?

Return to “Issues”