Results 1 to 8 of 8

Thread: how to enable/disable button in xt ajax

  1. #1

    Default how to enable/disable button in xt ajax

    Hello,

    I'm trying to enable/disable a button in my ajax handler as given below. But both cases, it is disabling the button. Any glue why is wrong here?
    If(some condition){
    SetAttributeAction action3 = new SetAttributeAction("buttonId","disabled","true");
    } else{
    SetAttributeAction action3 = new SetAttributeAction("buttonId","disabled","false");
    }

    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    Rome, Italy
    Posts
    347

    Default

    Quote Originally Posted by techluver View Post
    I'm trying to enable/disable a button in my ajax handler as given below. But both cases, it is disabling the button. Any glue why is wrong here?
    Try setting the "disabled" attribute only when you actually want to disable it; that is:

    Code:
    If(some condition){
    SetAttributeAction action3 = new SetAttributeAction("buttonId","disabled","true");
    } else{
    // do nothing
    }
    Cheers,

    Sergio B.
    Sergio Bossa
    Spring Modules Team

  3. #3

    Default

    Thanks for the reply.
    How can I enable the disabled button?

  4. #4
    Join Date
    May 2006
    Location
    Crawley, UK
    Posts
    105

    Default

    techluver,

    The important thing to realise about the 'disabled' attribute is that is is a boolean attribute. This is the case from more than one point of view.

    Firstly, it is boolean because it is either on or off - no other states are supported.
    Secondly, it is boolean because, when used in HTML it doesn't need an attribute value - it is its presence/absence that determines its state, not the value, any value that is supplied is effectively ignored.
    When dealing with XHTML, a value is required (To make the markup 'well-formed' XML), but (I think) it is also ignored.

    Anyway, what Sergio was trying to say is that a button is enabled when the 'disabled' attribute is not present at all.

    I hope this clarifies things.
    If you didn't learn anything today, you weren't paying attention!

  5. #5

    Default

    Thanks again.
    I understand how to disable the button.
    Still I dont get the answer for enabling the disabled button thru ajax.

    Some sample code please.

    Sorry for my ignorant If this is very simple to do.

  6. #6
    Join Date
    May 2006
    Location
    Crawley, UK
    Posts
    105

    Default

    Techluver,

    Sorry for misunderstanding your question.

    The issue that you have, with your current approach, is that there is no 'RemoveAttributeAction' class in the library.
    In order to implement this functionality, I'd suggest using the ExecuteJavascriptFunctionAttribute class instead.
    Using this, you can trigger the execution of a javascript function on the client side, that removes the 'disabled' attribute from the field with an id attribute of 'buttonId'.

    Code:
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("id", "buttonId");
            params.put("attributeName", "disabled");
            response.addAction(new ExecuteJavascriptFunctionAction("removeAttribute", params));
    Code:
            function removeAttribute(params){
                var formField = document.getElementById(params["id"]);
                if(formField != null){
                    formField.removeAttribute(params["attributeName"]);
                }
            }
    Admittedly, the provision of a 'RemoveAttributeAction' class would appear to be simpler and more succinct, so you should possibly submit a JIRA to request this.
    If you didn't learn anything today, you weren't paying attention!

  7. #7

    Default

    cool. Thanks a lot. JIRA for this : http://jira.springframework.org/browse/SEC-657
    Last edited by techluver; Apr 3rd, 2008 at 07:07 AM.

  8. #8
    Join Date
    May 2007
    Location
    Toulouse - France
    Posts
    6

    Default

    The JIRA entry is http: // jira.springframework.org/browse/MOD-457

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •