Not able to disable Submit button on event app.deactivated

4 Comments

  • Bryan - Community Manager
    Comment actions Permalink

    Hello Chaitanya Bojja -

    EDIT: You can indeed disable individual options using code such as the following:

    client.invoke('ticketFields:status.optionValues:open.disable')

    client.invoke('ticketFields:status.optionValues:open.enable')

    ...or for all options with this:

    client.invoke('ticketFields:status.disable')

    client.invoke('ticketFields:status.enable')

    You can see, however, that the larger 'Submit' button itself is still enabled. Currently, you cannot disable this button entirely.

    EDIT: client.invoke('disableSave') can be used to disable the entire button

    There have been requests to control and manage state better for use cases such as this. I encourage you to post a feature change request here: Developer Platform Feature Requests

    Apps can be a very important part of a business's workflow. I'll forward this request to product management as well.

    0
  • Bryan - Community Manager
    Comment actions Permalink

    An alternative that may be more reliable (but more work possibly) is create a trigger that calls a Target/webhook endpoint that performs the needed business process. This isn't always feasible, but is a possibility depending on the use case. Just wanted to be complete and mention it as a consideration.

    0
  • Chaitanya Bojja
    Comment actions Permalink

    Hi Bryan,

    I could be able to disable the larger  "Submit" button using client.invoke('disableSave') from the ticket_sidebar app as shown below. 

    But the issue is, I couldn't be able to use the same "client.invoke('disableSave')" inside the event app.deactivated as below:

    client.on('app.deactivated', function(data){
         client.invoke('disableSave');
    });

    I wanted to disable the larger "Submit" button immediately after the app gets deactivated.

    I wanted to do the following:

    Step 1: Open any existing ticket which has ticket_sidebar app as well

    Step 2: Click on "Reload all apps" button, observe that event "app.deactivated" gets triggered.

    Step 3: Inside the app.deactivated event, I wanted to use client.invoke('disableSave') to disable larger "Submit" button.

    Step 4: Then the ticket_sidebar app gets reloaded which fires the event "app.registered". Here inside the "app.registered" event I wanted to re-enable the larger "Submit" button using client.invoke('enableSave').

    0
  • Bryan - Community Manager
    Comment actions Permalink

    Gah! You're right on client.invoke('disableSave') - I've missed that option before in the documentation. Apologies about that.

    So let me backtrack then...

    Actually, I tried the approach you mentioned and it is working for me (for the most part). I have *a lot* of apps in my personal test instance (dozens) and while apps were being reloaded, I was able to disable the Submit button, then reenable it when the app loaded up again:

    Using this code:

    client.on('app.deactivated', (data) => {
    console.log("TEST app.deactivated fired")
    client.invoke('disableSave')
    })

    client.on('app.registered', (data) => {
    console.log("TEST app.registered fired")
    client.invoke('enableSave')
    })

    However, there are a couple of points to this:

    • The "disable" code doesn't run immediately -- there can be a delay for the code to run due to the nature of JavaScript and the asynchronous nature of running client.invoke
    • During one test run of mine, the deactivate/disableSave didn't fire for some reason
    • When I had only this app running, there was no discernible disabling and renabling of Submit -- this because the events happened so close together

    Given that, I think your approach is close to what you want, but not 100% guaranteed on the timing. And sometimes the event may not fire.

    Does this approximate your tests? Or is the button not being disabled at all?

    Going back to my original thoughts and the feature request that I submitted to product management is that there needs to be *guaranteed* state management around these events and control of UI objects such as Submit (without the delays and without relying on a specific app to do this work). Until then, an approach like this is going to be the next best thing possible.

    0

Please sign in to leave a comment.

Powered by Zendesk