Donnerstag, 12. Januar 2012

Disable a Dynamic action during runtime

Ok, I need a hint! So please show me a way...

In my last post I said that I would like to wrap up the "disable button" functionality and have it all handled in one ingle step.

In the meantime I encountered (at least) one major problem.

The only way I know to stop a button from firing a dynamic action is a condition.
So what I'm looking for is way to stop the button firing that dynamic action without a condition.

I thought that changing the button id could be an option.

if ($('#BUTTON_P1_TOGGLED').hasClass('apex_disabled')){
  $('#BUTTON_P1_TOGGLED').toggleClass('apex_disabled');
  $('#BUTTON_P1_TOGGLED').attr('id', 'P1_TOGGLED');
}else{
  $('#P1_TOGGLED').toggleClass('apex_disabled');
  $('#P1_TOGGLED').attr('id', 'BUTTON_P1_TOGGLED');
}

But that does not work. It looks like the binding is on another level even if the triggeringButtonId points to P1_BUTTON.

{"triggeringElementType":"BUTTON","triggeringButtonId":"P1_TOGGLED","bindType":"bind","bindEventType":"click",actionList:[{"eventResult":true,"executeOnPageInit":false,"stopExecutionOnError":true,javascriptFunction:function (){ alert('P1_TOGGLED is not disabled')},"action":"NATIVE_JAVASCRIPT_CODE"}]}];

So please give me a hint if you know a way to

  • enable/disable a dynamic action with Javascript or something else
  • have any other idea...
Dan's comment offered the clue I was looking for.

So I changed my code to



$('#P1_TOGGLED').toggleClass('apex_disabled');
if ($('#P1_TOGGLED').hasClass('apex_disabled')){
  $('#P1_TOGGLED').attr('disabled', 'disabled');
}else{
  $('#P1_TOGGLED').removeAttr('disabled');
}


and finally it worked. I will integrate this solution into my taming the button  example and come back with a packaged solution.

Thanks for the support guys.

Kommentare:

  1. Hi Martin,

    Did you try disabling the button? That will prevent the click event from firing.

    $('#P1_TOGGLED').attr('disabled', 'disabled');

    Regards,
    Dan

    AntwortenLöschen
  2. Hi Martin,

    you could do this with storing event handlers, unbinding them and then bind again, depending on some condition. But Dan's solution is easier...

    Br,
    Marko

    AntwortenLöschen
    Antworten
    1. Hello again,

      I switched the theme in my demo app back to Crimson-23 and it looks like the button renders as

      &lta id="P1_TOGGLED" class="uButton apex_disabled" disabled="disabled" role="button" href="javascript:void(0);"&gt
      &ltspan&gtToggled&lt/span&gt
      &lt/a&gt

      I don't know why, but the attribute disabled does not work here.

      Do you have a working exmple of your suggestion?

      Thanks Martin

      Löschen
  3. Hello Marko and Dan,

    thanks for the advice. As a wise man said: "You don't know what youd don't know". Now I know a little bit more. And believe me I was looking for exactly that clue for some time now.

    Br Martin

    AntwortenLöschen