Does a Form Method Exist???

Using the following code I’ve tried to see if a form method exists:

if(!_jsForm.getFormMethod('function onLoad (event){elements[buttonName].enabled = colValue}') )

But this is incorrect syntax and I get```
TypeError: Cannot call method “getFormMethod” of null


How should I construct the check for a form method in solution model code?

I’d just check if the function getFormMethod(name) returns anything on your form object for the name of the method.

Paul

Doesn’t your error say your form (_jsForm) is null?

pbakker:
I’d just check if the function getFormMethod(name) returns anything on your form object for the name of the method.

Paul

Thanks for the feedback. That’s really what I’m trying to do Paul - and I need the syntax to do that?

I guess in your example, the name would be ‘onLoad’ :)

But as Patrick points out, it looks like you didn’t get a proper reference to the JSForm…

Paul

pbakker:
I guess in your example, the name would be ‘onLoad’ :)

But as Patrick points out, it looks like you didn’t get a proper reference to the JSForm…

Paul

Heres what I get from the _jsForm property: com.servoy.j2db.scripting.solutionmodel.JSForm@9c3a21
So I dont think its null? Using this loop I can get it (thanks McCourt…)

var _jsForm = solutionModel.getForm(formName)
						//application.output(_jsForm)
						var methods = _jsForm.getFormMethods()
   							methods.forEach(function(x){if (x.getName()=='onLoad')
   							{
   								onLoadFound = true
   								application.output('On Load Found')}})

But I think there must be a simpler way?

var _jsForm = solutionModel.getForm(formName)
//application.output(_jsForm)
var method = _jsForm.getFormMethod('onLoad');

if (method)
{
     application.output("I load, therefore I am");
}
else
{
     application.output("onLoad does not exist.");
}

Also, I can’t help myself…if you really only had an array of methods to work with you’d want it to work like this…

var _jsForm = solutionModel.getForm(formName)
//application.output(_jsForm)
var methods = _jsForm.getFormMethods();

var match = methods.filter(function( x ) { return (x.getName() == 'onLoad') });

if (match.length > 0)
{
     application.output("Found " + match.length + " matches.");
}

Nice One - simpler for sure. Thanks

Posted a couple other questions on my (lack of) understanding of the SM - perhaps you can throw some light on it??

Cheers

jgarfield:
Also, I can’t help myself…if you really only had an array of methods to work with you’d want it to work like this…

var _jsForm = solutionModel.getForm(formName)

//application.output(_jsForm)
var methods = _jsForm.getFormMethods();

var match = methods.filter(function( x ) { return (x.getName() == ‘onLoad’) });

if (match.length > 0)
{
application.output(“Found " + match.length + " matches.”);
}

But isn’t this slow? Isn’t this really copying stuff every time? ;)

couldn’t help my self… got a déjà vu of ServoyWorld :)

jcompagner:
But isn’t this slow? Isn’t this really copying stuff every time? ;)

couldn’t help my self… got a déjà vu of ServoyWorld :)

:P

Hi

It is not “solution model code”. But couldn’t you use this anyway:

if (!forms[_jsForm].onLoad)

Regards
Birgit

birgit:
Hi

It is not “solution model code”. But couldn’t you use this anyway:

Code: Select all
if (!forms[_jsForm].onLoad)

Regards
Birgit

That would be a possibility, but this thread is more or less a spin-off of another thread… :)
The initial problem was a performance issue when looping through forms using the forms[_form] syntax.
This way all forms are touched, thus loaded, which caused the performance problem.

Ah, thank you. I wondered in what circumstance you cannot use this simple forms check.

Regards
Birgit