Widget as parameter

Widget as parameter

  
Is there a way to pass a widget as parameter to an action? More specifically, I have an address validation action that checks various components of an address for validity. If a component is not valid, I need to set the ValidationMessage of the pertaining widget to a specific error message. However, there seems to be no way to pass the widget to the address validation action. As a workaround, I have output parameters for each widget, but that means I need to check these after every invocation of the action, which kinda defeats the purpose of using an action to prevent duplicate code.
Hi Kilian,

I'm not sure I am understanding your specific scenario, but as I see it, you could try to create an Action that does all the validation you need, and then returns a boolean - IsValid - and possibly a detailed error message.

Then, on the screen you state that the widgets will be validated on Client-side and Server-side as well.

Finally, on the submit action, you can run that action, passing the address as a parameter, and marking the respective widget as being valid or not.

In the end of the action, you should check if the Parent Edit Record - or the widget, if it's just one - is valid or not, and proceed accordingly.

Does this answer what you're looking for?

Regards,

Paulo Tavares
Hi Paulo,

The problem is that I have multiple widgets that I want to set the ValidationMessage for, so a single "valid" status and/or a single error message does not suffice. But if it is not possible to pass widgets as an input argument to an action, I'll have to deal with it in a different way (unfortuntaly, due to the impossibility of calling a screen action from another screen action, this is rather cumbersome).

Best regards,


Kilian

Hi Kilian,

I am still unsure of having fully understood your scenario, but you can set an "IsValid" attribute in each widget you want, and set a ValidationMessage for each widget as well - as long as the widgets have the Name property set.

I hope this helps.

Regards,

Paulo Tavares
Hi Paulo,

Let me try to explain. My scenario is this: I have multiple screens that contain address information. On each of these screens there's the street name, door number, postcode and city. For each of these addresses I need to check the validity on saving the information (the addresses are part of different data, so saving them is independent of each other). I have an action, CheckAddress, that has as input parameter the record containing the address information (they're all in the same table), and performs the checks based on the data entered. Each of the screens that contains an address should mark each invalid field as such, i.e. by setting the IsValid of the pertaining widget to false, and setting the ValidationMessage to show when the field has the focus. Ideally, the CheckAddress action could take care of that, by setting those values for each widget if necessary. But there's no way it seems to pass a widget as parameter to the action, so that all CheckAddress can do is indicate somehow (by means of an output parameter) which fields are invalid and return (for each field) an error message. This means however that after calling CheckAddress, I have to go over all the output parameters and set the IsValid and ValidationMessage of the pertaining widgets, which means duplicating that code each time. And I'd like to avoid duplicating code, which is why I use an action in the first place, of course.

Best regards,


Kilian
Oh, I get it. Sorry for not getting it before.

Yes, the way I see it being done is as you say: the action returns several Valid parameters, and then, in an assign - in the screen action - set each is valid according to the result.

Regards,

Paulo Tavares