How to use the mobile javascript API class $public.Validation

How to use the mobile javascript API class $public.Validation

  

I would like to make a screen action that has a widgetId as input and perform a validation.

There are many simular fields on my screen to receive same validation.

I use a javascript flow like this:

if ($parameters.ErrorMessage === '') {
    $public.Validation.setWidgetAsValid($parameters.WidgetId);
} else {
    $public.Validation.setWidgetAsInvalid($parameters.WidgetId, $parameters.ErrorMessage);
}

See https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/JavaScript_API/Validation


However, this doesn't work. Did some debugging in chrome myself and see that the $public.Validation (singleton?) class has a private property _model that needs to be set.

Does anybody know how to correctly call this api?

Regards,

Daniel


Solution

Hello Daniël,

Here it is working perfectly:

And the page after clicking the button that calls the action that call the JavaScript:

What exactly is not working on your side?

Cheers.

Solution

Hi Eduardo,

It doesn't work, I get a javascript exception on the setWidgetAsInvalid, and if I debug it i notice that the $public.Validation class has a property _model which is empty. This model property has a widget property that it tries to access. as _model = null it cannot find the widget.

Maybe it is due to my special use case. We are building a mobile app that is used in the pc browser as we need the offline functionallity.

I noticed you tested it in the mobile emulator, I will give it a try in the emulator and see if it behaves differetly.

Anyhow thanks for confirming that it should be able to work correctly.

Regards,

Danniel

Hum...

Yeah. You are calling it correctly.
So, maybe this way of using the mobile app (it is not the first time I hear about it) does not work correctly...

Please, if you find a solution for your specific case, let us know :)

Cheers.

Hi Eduardo,

You've put me on the right track to identify where it went wrong in my solution.

I created a client action with the javascript flow element that called the $public.Validation functions.

I moved this to a screen action on the webblock where I need it and then it works. 

The scope of what is availabe in the screen action is different to a client action.

The only disadvantage is that I have a few webblocks, but then again it is limited amount of code.

Regards,

Daniel