Topic
10 replies Latest Post - ‏2013-07-08T16:00:02Z by Shu Sia Lukito
SystemAdmin
SystemAdmin
9029 Posts
ACCEPTED ANSWER

Pinned topic Submit Button (wanting to run a script as well as call a backend webservice)

‏2006-10-25T20:19:28Z |
I have a page that has two Selects and an input field and on clicking the [b]Submit button[/b]. I want to be able to run a javascript so that I can show some alerts as well as submit the form and call a backend service with inputs coming from the form. Whats the best way of doing this.
Updated on 2008-12-29T15:21:35Z at 2008-12-29T15:21:35Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    9029 Posts
    ACCEPTED ANSWER

    Re: Submit Button (wanting to run a script as well as call a backend webservice)

    ‏2006-11-08T19:49:40Z  in response to SystemAdmin
    One option would be to creating an Action List builder which would have the desired functionality (method that submits the form, or runs a script,etc..) you need, and then calling the action list from the button builder.
  • SystemAdmin
    SystemAdmin
    9029 Posts
    ACCEPTED ANSWER

    Re: Submit Button (wanting to run a script as well as call a backend webservice)

    ‏2006-11-08T20:01:38Z  in response to SystemAdmin
    Create your button builder normally. Note that this puts some javascript on the button. (You can see it in the WebApp Tree view, which you should be looking at a lot.) Then, create an HTML Action Builder, also targetted at the button.

    In the HTML Action Builder:

    PageLocation: <the button>
    Event Name: onClick
    Action Type: Run a Script
    Script to Execute: <Put your JavaScript here -- finish with a semi-colon>
    [b]Advanced section[/b]
    Overwrite Rule: Prepend new value
    • SystemAdmin
      SystemAdmin
      9029 Posts
      ACCEPTED ANSWER

      Re: Submit Button (wanting to run a script as well as call a backend webservice)

      ‏2006-11-08T20:02:25Z  in response to SystemAdmin
      Sorry, that should be an "HTML Event Action" Builder.
      • SystemAdmin
        SystemAdmin
        9029 Posts
        ACCEPTED ANSWER

        Re: Submit Button (wanting to run a script as well as call a backend webservice)

        ‏2006-11-21T23:28:57Z  in response to SystemAdmin
        Hi ,

        Did this method worked, I have to call a specifc ActionList from the javascript , depending on the values reurned by the javascript

        Regds
        Pras
        • SystemAdmin
          SystemAdmin
          9029 Posts
          ACCEPTED ANSWER

          Re: Submit Button (wanting to run a script as well as call a backend webservice)

          ‏2006-11-27T17:11:38Z  in response to SystemAdmin
          Hi. I tested it before posting, so I know it works.

          For your case, there are a couple of options. Probably the easiest one is to have a hidden input on the page, and then have your JavaScript set the value in the hidden input. Then set your button always to call a single Action List or Method, but all that Action List/Method does is test the value passed in the hidden input and invoke the correct action list that the JavaScript wanted to call.

          You could have the JavaScript construct the URL directly, by reverse-engineering our URLs to call an action list. I pretty stronly recommend against this approach, because it could easily break in a future release of the Factory. We do not guarantee that the URL format will remain consistant forever, but the technique I described above should always work.\
          • SystemAdmin
            SystemAdmin
            9029 Posts
            ACCEPTED ANSWER

            Re: Submit Button (wanting to run a script as well as call a backend webservice)

            ‏2008-12-26T03:13:31Z  in response to SystemAdmin
            Your method works Steve. It is just what I was looking for. Cool, learned something new about PF today.
            • SystemAdmin
              SystemAdmin
              9029 Posts
              ACCEPTED ANSWER

              Re: Submit Button (wanting to run a script as well as call a backend webservice)

              ‏2008-12-29T15:21:35Z  in response to SystemAdmin
              Thanks! I hadn't remembered writing this and was puzzled ... until I looked at the date I wrote it.

              It's great to see that people are searching the forums before posting. Thanks for that, too! :D
    • Shu Sia Lukito
      Shu Sia Lukito
      2 Posts
      ACCEPTED ANSWER

      Re: Submit Button (wanting to run a script as well as call a backend webservice)

      ‏2013-07-06T20:48:38Z  in response to SystemAdmin

      I tried this with a very simple model (see attached), but it doesn't work. It doesn't seem to run the JavaScript at all.

      My goal is to add a client-side javascript validation to run before the submit action runs. Upon submit, I have a service provider with Linked Java Object that will write back the information to the LDAP. For now, all the button did is to run an action that displays a success page. I originally tried to get this working with Page_NextAction and Data Fields Settings, but due to conflicts with the GUI code provided for me, I had to disable dojo (it seems to work if I use the base.xml for RDD, but not with dojo_base RDD). I also have to disable Smart Refresh because I'm using PUMA SPI in the LJO and got error getting ActionRequest if I don't disable it.

      Attachments

      Updated on 2013-07-06T21:58:53Z at 2013-07-06T21:58:53Z by Shu Sia Lukito
  • gsager
    gsager
    98 Posts
    ACCEPTED ANSWER

    Re: Submit Button (wanting to run a script as well as call a backend webservice)

    ‏2013-07-08T13:29:01Z  in response to SystemAdmin

    Yes the javascript doesn't seem to be inserted using the HTMLEventAction.

    Here is what is generated for that action with the HTMLEventAction and it disabled

    <input name="submit_btn" value="Save" onclick="wpf_ppr8003201307010637.load(document.getElementById(&quot;<%= com.bowstreet.webapp.IDGenerator.getCurrentID(webAppAccess, "wpf_action_ref_0") %>&quot;).href, [&quot;<%= request.getAttribute("bowstreet.smartRefreshID") %>&quot;], wpf_ppr8003201307010637.smartRefreshHandler, {execScripts:false, eventPfx: &quot;<%= webAppAccess.getInstanceID() %>Ajax&quot;})" type="button" class="wpfBlueButton">

    <input name="submit_btn" onclick="wpf_ppr8003201307010637.load(document.getElementById(&quot;<%= com.bowstreet.webapp.IDGenerator.getCurrentID(webAppAccess, "wpf_action_ref_0") %>&quot;).href, [&quot;<%= request.getAttribute("bowstreet.smartRefreshID") %>&quot;], wpf_ppr8003201307010637.smartRefreshHandler, {execScripts:false, eventPfx: &quot;<%= webAppAccess.getInstanceID() %>Ajax&quot;})" value="Save" type="button" class="wpfBlueButton">

    but if I add the javascript using the attributesetter builder I do get  the javascript inserted before the refresh so maybe try using the attribute setter instead of the HTML Event action and see if that gets you by this issue.

    <input name="submit_btn" value="Save" onclick=" alert('onclick html event');wpf_ppr8003201307010637.load(document.getElementById(&quot;<%= com.bowstreet.webapp.IDGenerator.getCurrentID(webAppAccess, "wpf_action_ref_0") %>&quot;).href, [&quot;<%= request.getAttribute("bowstreet.smartRefreshID") %>&quot;], wpf_ppr8003201307010637.smartRefreshHandler, {execScripts:false, eventPfx: &quot;<%= webAppAccess.getInstanceID() %>Ajax&quot;})" type="button" class="wpfBlueButton">

    Attachments

    • Shu Sia Lukito
      Shu Sia Lukito
      2 Posts
      ACCEPTED ANSWER

      Re: Submit Button (wanting to run a script as well as call a backend webservice)

      ‏2013-07-08T16:00:02Z  in response to gsager

      Thank you so much! It worked. Also, my co-worker pointed out that if I move the HTML Event Action builder under the Button builder, it worked too.