Last button clicked?

Is there a function like lastClicked()?

This is what I am thinking. A global type of function that would be able to determine where to go based on what was clicked. An onAction method would look like this.

switch ()
{
   case lastClicked(button, name == "My Button") :
      go somewhere;
   case lastClicked(button, name == "Your Button") :
      go somewhere else;
   case lastClicked(button, name == "Their Button")  :
      go crazy;
   default :
      say "You're lost";
}

syntax would be the follwing

lastClicked(objectType, property 1 [property n])

The cool thing about this type of function would not only be making a universal type of naviation, as above, but it would also allow you to watch for coordinates within images. For example.

if (lastClicked(image, location == 0,0,10,10){
 say "You clicked on my town"
}

When the image was a map and you clicked in the upper corner within 10 pixels of the top left edge.

Can this be done currently? Sound like a great function?

Sound like a ‘very nice to have kind of great thing’…

This is what I’m talking about in

If we were to have the “this” property or a “me” or a “self” (realbasic equivalent), it would be a whole lot easier to generalise your code, like in if (me.name == “somebtn”)
do this

And I think it would be real easy to implement. We need a notion of the “currentelement” (like the currentcontroller), and the elements name property would need to be public or a getElementName method would need to exist.

just my 2eurocents

your suggested me or self reference was what I was thinking of too… Although this would make much more sense, in my humble opinion, if we would have methods and events proprietary to the control (like in REALbasic). I guess…

just my 0.5 cents :lol:

the javascript specification does not support a way to get the name of current function (and we are limited to that)

Jan Blok:
the javascript specification does not support a way to get the name of current function (and we are limited to that)

Is the Servoy environment aware of its objects? If it were, could you use the plugin API to do something like this?

Yes Servoy is aware of the JS objects, there are currently only no back references between them… we could provide the initiating element as arguments[0] to your method and provide a getName() method on all elements.
so then you could do in your method:
var elementName = arguments[0].getName();

to get the current element name starting this method.
whould that help?

when I do
var x = elements[0]

x can be DataField[NameofField:DataProvider],
or ScriptButton[Name]
or ???

however I’m don’t seem to be able to retrieve the items inside the ( without using regex) hence my question for a getName().

elements seems to be an alfabeticaly ordered array(Please correct me if I’m wrong). I would like to see it ordered (optionally ?) by TabSeq and the TabSeq property retrievable by a method (getTabSeq()) or as a Public property.

This would “connect” the programming logic with the user interface logic and introduce concepts as the “next” and “previous” element ( as seen by the user of the form)

please, pretty please…

we did settle on an extra method on application: getMethodTriggerElementName()

so you can test if a button X of button Y is pressed for that method (or dataChange on a fields)

to get the element itself:
elements[application.getMethodTriggerElementName()]

you have to specify the name ofcourse else the name will return null.

since we submitted in the exact same minute, would you please also react on my point 2 (pref with the words: great idea we are implementing this as we speak, or something along those lines) :lol:

Jan, your suggestion would help!

I think all that would give us the possibility to ‘know’ what object/element started something would help us. Although, it could be important but it doesn’t keep me from doing what needs to be done! Yet :?

We have added application.getMethodTriggerElementName() which returns the name of the element being the source. (which is easier than passing the element as argument)

With the name you can lookup properties like:
var elementText = elements[application.getMethodTriggerElementName()].text;
var bgcolor = elements[application.getMethodTriggerElementName()].bgcolor;
etc.

Addionally we will provide getName() on all elements

tip:
If you want to start using elementnames on a global level you might need the form name as well (formName + elementName makes a unique String)

  1. global script name = getElementName
    var elementName = application.getMethodTriggerElementName()
    var formName = arguments[0]

  2. button script somewhere in a form
    globals.getElementName(currentcontroller.getName());

explanation:
If you click the buttonscript, the global script will be triggered AND it will receive the argument “currentcontroller.getName()” which is the form where the button was clicked.

Jan Blok:
Addionally we will provide getName() on all elements

That’s a good start that will get of half way there to image maps and it solves the issue of making global methods to handle multiple buttons.

All this, of course, is coming in newer versions right? Will it make 1.2 final?

Coming back to an old topic, is it a) possible, b) useful, to allow an optional argument to an OnAction method in the form editor. In this way, the method called by the click can behave differently, depending on the argument(s) passed. Saves having to name each button for the GetTrigger… function.

Nope, not possible other than (maybe) using the text attribute of the button and changing the text after an action. Like, for example, set the text of a button to ‘open’ and change it to ‘close’ when the button was clicked. As a result you can do different things when you read the text.

Not currently possible, is it a good feature request, perhaps?

useful and possible.
I’ve discussed this with Jan Blok some time ago.
The idea is to have a property on a button that you can fill with arguments.
These arguments are automatically sent onClick, to the (global) script that’s attached to the button.

  1. Saves you declaring a local script that sends arguments to the global script
  2. You don’t have to “mis use” element names in order to get information across the system.

Will see if we can push this up the prio list a bit :wink:

EXCELLENT! Thanks for considering it. Servoy responsiveness at its best.