Server submit without button

Server submit without button

  

Hi,

Is there a way to submit variables to the server without a button or link?

I'm populating an input box using Javascript, but the value doesn't get saved unless a submit action is performed. Is there a way to automatically submit the values to the server? The OnChange function applied to the input box also does not seem to be working.

Thanks!

Hi Saurav,

The Screen Action you assign to OnChange should be called when the user types text inside the input widget (if I'm not mistaken, there's a slight delay after the last key press, so as not to trigger too many requests to the server). But that relies on user input, which you're bypassing by populating the input widget via JavaScript.

A typical solution for this kind of scenario is you add an invisible button (call it for instance YourButton and place it inside a Container with Display property set to False), and in your JavaScript (after you populate the input widget) you use something like:

"$('#" + " + YourButton.Id + "').click();"

Next you'd just need to setup the Button's On Click Destination and Method properties according to your needs.

Would this do the trick for you?

Jorge Martins wrote:

Hi Saurav,

The Screen Action you assign to OnChange should be called when the user types text inside the input widget (if I'm not mistaken, there's a slight delay after the last key press, so as not to trigger too many requests to the server). But that relies on user input, which you're bypassing by populating the input widget via JavaScript.

A typical solution for this kind of scenario is you add an invisible button (call it for instance YourButton and place it inside a Container with Display property set to False), and in your JavaScript (after you populate the input widget) you use something like:

"$('#" + " + YourButton.Id + "').click();"

Next you'd just need to setup the Button's On Click Destination and Method properties according to your needs.

Would this do the trick for you?

It works, but the preparation keeps running again and again. I don't understand why the page is refreshing endlessly. Any ideas?

Solution

hi Saurav,

I think you need a screen variable that toggles to true and false when the server action (submit) has been done as the preparation action is called over and over again.

if var = true...do the "$('#" + " + YourButton.Id + "').click();" else none

regards,

bb


Solution

Saurav Sircar wrote:

Jorge Martins wrote:

Hi Saurav,

The Screen Action you assign to OnChange should be called when the user types text inside the input widget (if I'm not mistaken, there's a slight delay after the last key press, so as not to trigger too many requests to the server). But that relies on user input, which you're bypassing by populating the input widget via JavaScript.

A typical solution for this kind of scenario is you add an invisible button (call it for instance YourButton and place it inside a Container with Display property set to False), and in your JavaScript (after you populate the input widget) you use something like:

"$('#" + " + YourButton.Id + "').click();"

Next you'd just need to setup the Button's On Click Destination and Method properties according to your needs.

Would this do the trick for you?

It works, but the preparation keeps running again and again. I don't understand why the page is refreshing endlessly. Any ideas?

The Preparation always runs (and the full screen re-renders) when you use the "Submit" Method and your screen action ends with an End tool.

If you don't want the Preparation to run again, you should change your Button's Method to "Ajax Submit", but be careful as the screen will not be re-rendered unless you explicitly use the Ajax Refresh tool in your Screen Action. I would suggest you go through the Screen Lifecycle: Interaction and Screen Lifecycle: Ajax Interaction lesson of the Developing OutSystems Web Applications course to learn a bit more how regular Submit and Ajax Submit work in OutSystems.

Jorge Martins wrote:

Saurav Sircar wrote:

Jorge Martins wrote:

Hi Saurav,

The Screen Action you assign to OnChange should be called when the user types text inside the input widget (if I'm not mistaken, there's a slight delay after the last key press, so as not to trigger too many requests to the server). But that relies on user input, which you're bypassing by populating the input widget via JavaScript.

A typical solution for this kind of scenario is you add an invisible button (call it for instance YourButton and place it inside a Container with Display property set to False), and in your JavaScript (after you populate the input widget) you use something like:

"$('#" + " + YourButton.Id + "').click();"

Next you'd just need to setup the Button's On Click Destination and Method properties according to your needs.

Would this do the trick for you?

It works, but the preparation keeps running again and again. I don't understand why the page is refreshing endlessly. Any ideas?

The Preparation always runs (and the full screen re-renders) when you use the "Submit" Method and your screen action ends with an End tool.

If you don't want the Preparation to run again, you should change your Button's Method to "Ajax Submit", but be careful as the screen will not be re-rendered unless you explicitly use the Ajax Refresh tool in your Screen Action. I would suggest you go through the Screen Lifecycle: Interaction and Screen Lifecycle: Ajax Interaction lesson of the Developing OutSystems Web Applications course to learn a bit more how regular Submit and Ajax Submit work in OutSystems.

Ajax refresh doesn't seem to be working for some reason. But Barong Bali's solution worked out fine. :)


I'm glad you worked out a way of making it work. Nevertheless I'd like to understand why an Ajax Submit with Ajax Refresh isn't working for you.

Barong Bali's solution works, but using an extra Local Variable flag is usually an unnecessary hack if you've designed your screens correctly (although some specific scenarios may indeed require it).

Is the JavaScript that populates the input widget and calls the button being refreshed as part of the Ajax Refresh?