Page 1 of 1

Set Menu Response via JavaScript

Posted: Tue Dec 31, 2013 12:53 pm
by DaveLClarkI
I have a context menu to provide various choices. However, I also want to be able to use row double click as an alternate means of performing one of the choices on the context menu -- i.e., without actually having to use the context menu. But, my RPG code still expects to see a value in the menu response field. Now, I see the changeElementValue() API but will that work on the value of a bound field?

So, the question is, how can I use JavaScript to set the menu response field and submit it? Thanks.

Re: Set Menu Response via JavaScript

Posted: Tue Dec 31, 2013 1:40 pm
by Scott Wagers
The changeElementValue() API doesn't work directly with a menu widget, but there is a way to accomplish what you're trying to do.

First you could bind a value to the 'menu response' property. Then you could add a hidden textbox widget which will work w/changeElementValue() and bind it's value to the same field as the 'menu response'. You could then set the textbox widget's value with JavaScript changing the value for the context menu as well.

Does that make sense?

Re: Set Menu Response via JavaScript

Posted: Tue Dec 31, 2013 2:22 pm
by DaveLClarkI
I understand what you're suggesting and I just tried it -- but it didn't work.

I have a context menu called "mnuContext" which has its "menu response" property bound to "mnuOption" and I created a hidden output field called "outOption" and bound its "value" property to "mnuOption" as well. Then, I have the following code in the "onrowdblclick" property.

Code: Select all

  changeElementValue("outOption", "Select");
  pui.click("lnkSelect." + row);
I put my RPG program in debug and the correct row is read as a changed row (that is what clicking the hidden link accomplishes) but the "mnuOption" field is blank.

Now, I do have an open issue (Issue #451) with a similar problem where two menu widgets are bound to the same "menu response" field (the first is a context menu for right-click on the grid row and the second is a pop-up menu for left-click on a gear image widget) and the second menu widget isn't setting the response field. Is that the same problem in this case?

Re: Set Menu Response via JavaScript

Posted: Tue Dec 31, 2013 2:37 pm
by DaveLClarkI
Well, the problem appears to be different in this case. I tried changing the hidden output field called "outOption" by binding its "value" property to a completely new field called "mnuOption3" but when I run in through debug "mnuOption3" is blank. Now what?

Re: Set Menu Response via JavaScript

Posted: Tue Dec 31, 2013 2:39 pm
by David
The problem is that you are using a hidden output field, which is not input-capable.

Try a textbox...

Re: Set Menu Response via JavaScript

Posted: Tue Dec 31, 2013 3:03 pm
by DaveLClarkI
OK, now I have the same problem as Issue #451. If I bind the hidden text box to the same "menu response" field as the context menu, then that field is blank when RPG sees it. If I bind the hidden text box to a new response field, then RPG receives the desired value just fine.

So, just for fun, I tried binding the hidden text box to the same "menu response" field as my pop-up second menu and that exhibits the same problem as with the context menu. I was hoping it was just a context menu issue and not an "all menus" issue. Now I have two reasons for needing a fix to Issue #451.