Page 1 of 1

pui.click from RPG

Posted: Tue Sep 29, 2020 12:31 pm
by charles.wilt
We added a hyperlink widget to one of our existing screens..

Working great. Except that this screen also has a "Function" input box that the users use to select various functions via the keyboard. For example, the user enters a "90" into this function box and presses enter to start the closing process for the invoice currently in-process on the screen.

Product wants the "Function" "LC" to act the same as the user clicking on the hyper link.

I found this post from Scott, https://core.profoundlogic.com/forum/vi ... 5751#p5751

Which confirmed my original thoughts about the feasibility and validates one of the solutions I was considering.

However, since the post is 6 years old, I figured I'd check to see if there's any newer options.

Also, the alternative option I was thinking about was some sort of "onsubmit" function that looked to see if "LC" had been entered in the "Function" textbox. Is the a better or even viable alternative? Or should I just go with the autoclick on-load option as shown in the referenced post?

Thank you!

Re: pui.click from RPG

Posted: Tue Sep 29, 2020 1:22 pm
by Scott Klement
Charles,

If the goal is to open a URL in a new window, you can use the JavaScript window.open() to do that. (Or, if you want it to open in the same window -- which would end your current IBM i session if the URL is something the browser can display -- you can do it with the pui.link() API.)

As for whether you do it during the onload vs. onsubmit event. (Or anywhere else, such as onclick, onkeydown, onblur, etc) that's really up to you. It depends on how you want your application to behave, so is a matter of preference.

Re: pui.click from RPG

Posted: Tue Sep 29, 2020 3:32 pm
by charles.wilt
It depends on how you want your application to behave, so is a matter of preference.
We want the user to be able to type "LC" in the function input textbox and press enter, and have the URI opened in a new tab/window. (Actually, the tab doesn't open to a web page. There's a 3rd-party protocol handler that gets invoked by the browser. Weird, but working fine when the user actually clicks the hyper-link.)

I don't consider myself enough of a PUI expert (or PUI+JS) to have a preference on how that is accomplished :)

The solution of yours I referenced makes perfect sense, the only downside I see is an extra round-tip to/from the IBMi.

The onsubmit idea was just a thought, but after reviewing the profound docs for that event, I suspect I'd be misusing it in this use case.

Thus looking for guidance form the experts.

Re: pui.click from RPG

Posted: Tue Sep 29, 2020 4:43 pm
by Scott Klement
You don't have to do a round-trip to the IBM i if you don't want to.

Some alternatives:
  • Do it in the onload event (requires round trip to IBM i.. so maybe not optimal for you)
  • Check in the onsubmit event (as you suggested) return false to prevent screen submission
  • Set up a key event handler, and handle the ENTER key.
The difference between an onsubmit vs. key event handler in this case is that the submit can be fired by mouse clicks (such as a button that submits the screen, et al.) or by any function key. With a key handler you could restrict it to just the ENTER key.

If you decide to do a keyboard handler, you should decide whether it applies to the entire screen, or just one particular widget. i.e. do you want to handle the enter key no matter where the cursor is, or do you only want to handle it if the cursor is currently in a particular element (such as the textbox where they typed "LC"). Enter can behave completely differently depending on where the cursor is -- this isn't green-screen ;-)