Alpha Video Training
Results 1 to 10 of 10

Thread: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

  1. #1
    Member mixter's Avatar
    Real Name
    Michael Merlin
    Join Date
    Sep 2011
    Location
    Melbourne, Australia
    Posts
    220

    Default Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    OK this might be slightly tricky, I am stuck, so time for another forum post, yay!


    I have a ButtonList

    followed by two regular Buttons, let's call these Button1 and Button2

    What I am trying to achieve is...



    in the ButtonList.OnClick event

    first I run some javascript


    then I want to trigger in turn, the Click event for Button1 and Button2


    Button1 runs Server-side Xbasic which outputs Javascript to the client via Ajax callback


    Button2 opens a linked grid using Action Javascript.

    I can trigger Button2.Click from my ButtonList.OnClick easily enough

    because in the builder for the Button2 Edit Click Event
    I just press "view javascript" and see it is just this line of javascript
    {grid.componentName}_2A635A2E777D4D1D88E88F6E919FAD1F(this);



    But my problem is Button1

    The Button1.Click event is Xbasic

    Can I trigger it's click event using Javascript?

    I tried putting the following line into my ButtonList.OnClick but it did nothing

    Code:
    {dialog.object}.runAction('serverside_25e008027bbc4499a84542214401afb2');

    I got that long string from the Button1.Click Xbasic event window
    (see picture below)
    HowToTriggerThisEventFromButtonListOnClick.png

    and I thought I would try and trigger via that long name, by using
    {dialog.object}.runAction


    Is what I want to do even possible?

    i.e. Use ButtonList.OnClick event to in turn
    trigger the Button1.Click that uses Ajax callback to run XBasic on the server and return Javascript to the browser

  2. #2
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    This is in a UX right? If so, check out:
    Code:
    {dialog.object}.buttonClick('BUTTON_1');
    //Click the button in the 3rd row of a Repeating Section
    {dialog.object}.buttonClick('BUTTON_1:3');

  3. #3
    Member mixter's Avatar
    Real Name
    Michael Merlin
    Join Date
    Sep 2011
    Location
    Melbourne, Australia
    Posts
    220

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    Oh mannnn, that's so easy now I know how. Worked perfectly.

    Thanks Jinx, you rock!

    You're my main mouse

  4. #4
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    No problem,
    The runAction is for javascript actions (not action javascript which is inside individual events) that you create. If you go to your UX properties pane on the left of the builder and look under "Javascript" you will see "Javascript Actions" and you can build them there. You can then use runAction and the name of your action to run them within your UX.

    As for button clicking. Just an FYI as people run into snags with this, the button click method won't work on buttons that are hidden on the server-side since the buttons don't exist after render. If you hide them client side it will still work. This can be handy so you can create one button that get's clicked from multiple buttons or rows so you don't have to keep rewriting the code. You can also use Jquery/Javascript that's built in to Alpha:

    Code:
    $('DLG1.V.R1.BUTTON_1').click()
    And variants thereof to do what you'd like.
    "$" in the above case is really short for document.getElementById

  5. #5
    Member mixter's Avatar
    Real Name
    Michael Merlin
    Join Date
    Sep 2011
    Location
    Melbourne, Australia
    Posts
    220

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    So then can I also run any Javascript Function that I write, using runAction? I will check it out.

    And yes as for the buttons that are only called externally for their click events, I used CSS to hide a few things, with style =
    display: none;

    I quickly realized the controls fully disappear, events and all, if setting the Hide checkbox to true

    Thanks for all the tips. Just got my app to the next completion stage, cookin with gas now

  6. #6
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    JavaScript functions are a different beast. Yes, you can write a function and call it (including passing variables into it) but it is not the same as an action and, AFAIK, can not be called by "runAction". Think of Alpha's JavaScript actions as Action JavaScript that can be called from any event instead of just in the individual event in which it was defined. Yes, you can do that with functions but functions are straight code. The other two types are Alpha's way to build that code for you.

  7. #7
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,040

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    Guys while you're at it can you check if writing {dialog.Object}.buttonClick( then doing CTRL-Down Arrow brings up the list of buttons in your UX?

  8. #8
    Member mixter's Avatar
    Real Name
    Michael Merlin
    Join Date
    Sep 2011
    Location
    Melbourne, Australia
    Posts
    220

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    I think the {dialog.Object}.buttonClick will only trigger a named Button control

    But if you created a Button control that in turn ran it's own javascript to do CTRL-Down Arrow you might be able to do it.

    e.g. http://stackoverflow.com/questions/5.../596580#596580
    Code:
    function simulateKeyPress(character) {
      jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(0) });
    }
    
    $(function() {
      $('body').keypress(function(e) {
        alert(e.which);
      });
    
      simulateKeyPress("e");
    });

  9. #9
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,040

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    Hi Michael i think you misunderstood my question.
    A feature i use a lot in Alpha Anywhere is the ctrl-down arrow that gives you a list of available controls that fit the command you are using.
    For instance, write {dialog.Object}.setValue( then press ctr-down arrow and you will see the list of available controls in your ux, then selecting one control will copy it's name to the setvalue command.
    Although the help for buttonClick() states this feature is available, when i tried in buttonClick it didn't popup anything, that's what i wanted you to try...

    Nevertheless, your simulateKeyPress function will prove extremely useful :-)

  10. #10
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: Possible to use Javascript to trigger an Xbasic Button.Click event from a ButtonList.OnClick event?

    Jaime,

    You have to delete everything out of the method before the ctrl down will work. For instance, if you copy and paste this into your event:
    Code:
    {Dialog.object}.buttonClick()
    and then go between the parenthesis, it should work, but if you copy and paste this into it:
    Code:
    {Dialog.object}.buttonClick('BUTTON_1')
    it won't show up. At least until you delete everything in between the parenthesis.

Similar Threads

  1. xbasic event for button click dialog
    By chadbrown in forum Application Server Version 11 - Web/Browser Applications
    Replies: 7
    Last Post: 09-13-2012, 10:19 AM
  2. Dialog XBasic - Call the OnClick event of a button
    By kingcarol in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 02-07-2012, 12:18 PM
  3. Call onClick event of a button with Xbasic from Detail View
    By kingcarol in forum Application Server Version 10 - Web/Browser Applications
    Replies: 6
    Last Post: 09-12-2011, 12:57 PM
  4. Trigger the OnClick event of a button from Xbasic
    By kingcarol in forum Application Server Version 10 - Web/Browser Applications
    Replies: 9
    Last Post: 03-15-2011, 03:43 PM
  5. Video : Calling a button onclick event in Javascript
    By Bob Moore in forum Application Server Version 10 - Web/Browser Applications
    Replies: 4
    Last Post: 02-19-2010, 03:49 PM

Bookmarks

Posting Permissions

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