Function getDataProviderID() warning

I have this line of code that is giving me an error:

var source = event.getSource().getDataProviderID();  //Warning: The function getDataProviderID() is undefined in this script

The example code for getSource() makes it look like this is acceptable:

JSEvent.getSource(): Object
returns the source component/element of the event.
If it has a name the getElementName() is the name of this component.
var sourceDataProvider = event.getSource().getDataProviderID();

Am I missing something? When I try auto-complete after getSource() nothing comes up. Do I need to declare something?

Thanks!

gldni:
I have this line of code that is giving me an error:

var source = event.getSource().getDataProviderID();  //Warning: The function getDataProviderID() is undefined in this script

The example code for getSource() makes it look like this is acceptable:

JSEvent.getSource(): Object

returns the source component/element of the event.
If it has a name the getElementName() is the name of this component.
var sourceDataProvider = event.getSource().getDataProviderID();



Am I missing something? When I try auto-complete after getSource() nothing comes up. Do I need to declare something?

Thanks!

Please open a case in our support system about this (http://www.servoy.com/s) , event.getSource() returns an Object type, this is why no autocompletion is available. However this is just a warning, you can call that method just fine (if the source is indeed an element).

The source of an event can be many things, thus it has a very generic type Object.

You need to check the type of the source and “cast” it, in order to get rid of the warning. For example:

if (event.getSource() != null && event.getSource() instanceof RuntimeTextField) {
/**@type {RuntimeTextField}*/
var source = event.getSource();
var dp = source.getDataProviderID()
}

The sample code should show this, will get that updated.

Paul

Thanks for the help, guys. Do I still need to file a case for event .getSource() no auto-completion?

No, the problem is not missing auto-complete, but incorrect sample code, without type checking and “casting” through JSDoc.

.getSource() correctly returns “Object” as type, because the source of the event can be anything: RuntimeForm, RuntimeRadio a bean instance etc. The lowest common denominator for all these types is Object.

I have already created the case internally to get the sample code updated.

Paul

pbakker:
The source of an event can be many things, thus it has a very generic type Object.

You need to check the type of the source and “cast” it, in order to get rid of the warning. For example:

if (event.getSource() != null && event.getSource() instanceof RuntimeTextField) {

/**@type {RuntimeTextField}*/
var source = event.getSource();
var dp = source.getDataProviderID()
}




The sample code should show this, will get that updated.

Paul

Very helpful, thanks!

Cheers,
Maria