How to properly use web blocks

I have a screen MovieDetail with a form to create and edit a Movie. But then I have another screen that has a form and in this form, the user can select a Movie in a combo box, but next to this combo box there is a "Add new Movie" button. When this "Add New Movie" button is clicked it should appear a popup and in this popup should appear the form of the MovieDetail screen, so the user can create a new movie.


So, maybe this is a good case to web blocks, to reuse the same form in the MovieDetail screen and in the other screen. But I'm not understanding how to properly achieve this. First, it should be necessary to create a new web block, for example, "CreateMovieForm", that contains only the form to create/edit a movie. But then what is necessary? Is necessary to remove the form from the MovieDetail screen and drag the web block "CreateMovieForm" to the MovieDetail screen? But then in the "Add New Movie" button in the destination property is not possible to select the web block, so how to bind the button with the popup?

Solution

Hello Oscar,

Yes, this is a good use case for a web block.

You have to remember two things.

1. Web Blocks can't be "requested". You can place them in screens and other web blocks but never can call a web block direct from the browser.

2. You need to pass to the web block everything he needs.

In your case, you just need to pass the MovieId (a valid one to edit or NullIdentifier() if you want to add a new movie). The rest will be pretty much the same as it was in the Movie Detail.

In the case of the Popup, you will use the Web Block inside the Popup screen. Or in a Modal if you are using one.

Hope this helps.

Cheers.

Solution

Thanks! But so what should be the destination of the button "Add new Movie" (the button that when is clicked the popup should appear)? Because if the form is a web block and the web block can´t be used in the destination since it's not a screen I'm not understanding how this "Add New Movie" should be configured to show the popup with the form to create a new movie.

Hi Oscar,

The "easiest" but not the best approach would be to just call the MovieDetail screen.

You can have a new screen, use a Layout Popup instead of the standard (with the block in it) and call it with the link (navigation), associated to a Popup_Editor widget (until version 10 would be the case).

Or you can use a Modal in the screen and put the web block inside it, and then the Add New Movie would call a screen action (with Ajax Submit) and in you would use the ToggleModal to show the modal. In this case, you have to remember to "Ajax Refresh" the web block. To close the modal, you would have to trigger an Event (inside the block), that would be captured by its handler (in the page) and call again the ToggleModal to close it.

I think these three are pretty much the options you have here...

Cheers.

Thanks! But so using a web block like this both the Web Block and the MovieDetail screen will need to have the MovieId input parameter, the preparation with the aggregate GetMovieById, and the Save screen action to store/edit the movie right?

Hi Oscar, 

No. The MovieDetail will need the input parameter because you call the page, not the web block inside it, but all the rest will be inside the web block.

Cheers.