Is it possible to call a web block?

What I am looking for is the ability to call logic that is specific to the block without reimplementing it outside of the block.  Essentially it's part of my validation logic prior to a save.

The way it is currently implemented is for the web block to send the ID of a button in the block, and for the outer form to click the button (in JavaScript) and trigger the logic, but this seems to be a round-about way to do that.

Is there a better way?

Ian Johnstone wrote:

What I am looking for is the ability to call logic that is specific to the block without reimplementing it outside of the block.  Essentially it's part of my validation logic prior to a save.

The way it is currently implemented is for the web block to send the ID of a button in the block, and for the outer form to click the button (in JavaScript) and trigger the logic, but this seems to be a round-about way to do that.

Is there a better way?

Hi there Ian.

You can use the component "events".

And in your action, you start the trigger and it will call your action of your webblock.

In your webBlock, you need create the "Events\EventHandler".

And in your action of your screen, you need create the "Trigger" for your event.

For you pass the value for your event, you need use the actions (ProvideArgument...)

And the first action of your Event need is (GetArgument...).

Regards,

Carlos Alfradique


Hi Ian, 

that's the only way of doing it unless you can encapsulate the validation code in an action that can be called on the webblock and on the page.

Regards,

Marcelo

Hello Ian

I'm curious...
Why do you need to call a Screen Action "inside" a web block from the page?

As the web block does not have access to the parent, you are not "reusing" some logic, but just executing the logic inside the context of the web block...

What is your logic doing?

Or it is just a matter of calling a server-side validation before saving, for example?

Depending on what you're trying to accomplish, may exist other options.

Cheers.

Eduardo Jauch wrote:

Hello Ian

I'm curious...
Why do you need to call a Screen Action "inside" a web block from the page?

As the web block does not have access to the parent, you are not "reusing" some logic, but just executing the logic inside the context of the web block...

What is your logic doing?

Or it is just a matter of calling a server-side validation before saving, for example?

Depending on what you're trying to accomplish, may exist other options.

Cheers.


Hi Eduardo,

I created web block for handling address like (Address1, 2, City, State and country). I want to use this block in 

Billing and shipment screen. In that screen billing and shipping, both do have an address. But the save action

is on the screen. So, I need to validate both block's fields and save to entity.

Thanks & Regards,

Sudhakar

Ok, probably is the same use case ian,

Web blocks were not designed with validation in mind, it seems, as there is no "standard" way of dealing with this. 

The most "elegant" way is indeed the use of the "events" component. The problem I see with it is that it uses undocumented features of the platform, and they are undocumented for a reason. You may get stuck with a version because of this, even if for a while only. Or worse.

Other possibilities are:

1. The web block is used as an interface only. Every information is sent back to the parent using OnChange and in case of validation fail the web block is reconstruct accordingly, to show the validation messages.

2. You have a hidden button/empty link that executes a screen action to save data, and uses JavaScript to "click it".

The solution adopted, including variations of the above, like adding  an extended attribute or class to select the hidden button/empty link with JavaScript (jQuery) to avoid having to keep track of IDs, will depend on the specific needs.

One thing to take into account is that solutions involving call web block screen actions to validate data before a save, if there are also data from the parent to be saved at the same time, will require the parent to be aware if it can dave the data or not,and this will require triggering events from the web block and only than checking if is possible to save, with potential increase in complexity in case of multiple web blocks, what will require extra logic.

Than I prefer the solution 1, where the data is kept in the parent, and the web block just gather info and show info, controlled by the parent that refreshes the web block when needed passing relevant information so that it can set the validation and validation messages of its inputs.

I purposely left out any solution using FakeNotify as I don't know if it is still recommend its use in version 11.

Hope this helps

Cheers

Thanks all.  

Solution #1 will not work in my case due to the way things are organized. The only solution appears to be to click something with JavaScript with a validation result event/trigger that tells the outer "caller" Yes/No for validation.