· Dec 14, 2015

Zen Mojo - Disable button on JQM Plugin

Hi All,

I am trying to disable a button on a JQM application.

I started the button as disabled according to this code: {type:'$button',caption: Button',key:'button',disabled:true}

However, I would like to enable or disable the button via JavaScript code . I have tried the following, but it don´t have the same behavior and style as the code above.  

var view = zen('mainView');

I expect to get the same component behavior of {type:'$button',caption:'Standard Button',key:'button',disabled:true} when enabling or disabling the button through JavaScript code. I mean, the same style, color, behavior, etc.

I have also attached a basic test that I have done.

Can anybody help me please?


Discussion (2)0
Log in or sign up to continue

Hi Fabio and Bernd,


is really just a shortcut for 


Both only work on standard control elements, and only *if* the library rendering the widget in question don't add special logic. jQueryMobile implements their own styles and behavior for disabling and enabling elements, therefore, it is the most stable approach to leverage the jQM logic.

A long discussion regarding this topic can be found here:

Let's walk through this in the ZM.jQM145.HomePage.cls demo and disable/enable the main button with the caption "Start demo".

var view = zen('mainView');

var button = view.getItemByKey('start-show');

var id = button.$findElement().id;



Line 1 retrieves the documentView component while line 2 retrieves the button layout object. This is pretty basic. 

In order to run jQM logic we have to find the HTML DOM element we want to disable/enable with the $() method from jQuery. As it requires the physical id that Zen Mojo generated for us we store that in a local variable id in line 3.

Line 4 now looks up the jQM widget and disables it with the supported jQM library call. Line 5 enables the button again.

In the future, we may add support for $disable and these special library calls as we have done for $show and $hide. $show and $hide work on any widget from any supported plugin.