How to Display View/Edit Page in Modal Dialog that Belongs to Another Tables (v2021)

Tips submitted by PHPMaker users
Post Reply
mobhar
User
Posts: 11660

How to Display View/Edit Page in Modal Dialog that Belongs to Another Tables (v2021)

Post by mobhar »

This following code will show you how to display the View/Edit page in modal dialog that belongs to another tables by using PHPMaker v2021. Actually, this trick is working also in v2020, but this time I obviously chose v2021, since I used the specific link to open the page in Modal dialog that only working in v2021 (which supports URL rewrite). If you want to implement this for v2020, then you need to adjust the url param from code below.

For simplicity, we need to use demo project that you may download and try by yourself for PHPMaker v2021: https://phpmaker.dev/demo2021.zip

So, we want to display Modal dialog to open View page of orders table for OrderID field from orders2 List page... and also open Edit page of customers table in Modal dialog for CustomerID field in orders2 List page.

  • Just copy this following code in Row_Rendered server event that belongs to orders2 table:

        if (CurrentPageID() == "list" || CurrentPageID() == "view") {
        	$this->OrderID->ViewValue = "<a href='#' onclick='ew.modalDialogShow({lnk:this,url: \"orders/view/".$this->OrderID->CurrentValue."\",btn: \"ViewBtn\"});'>" . $this->OrderID->ViewValue . "</a>";
        	$this->CustomerID->ViewValue = "<a href='#' onclick='ew.modalDialogShow({lnk:this,url: \"customers/edit/".$this->CustomerID->CurrentValue."\",btn: \"EditBtn\"});'>" . $this->CustomerID->ViewValue . "</a>";
        }
  • Don't forget to re-generate ALL the script files, as usual. ;-)

  • Now login using username/password: admin/master from the generated web application, then go to orders2 List page. As you can see, when you click on link in OrderID from orders2 List page, it will open View page of orders table in Modal dialog

  • The similar thing also for CustomerID; will open Edit page of customers table in Modal dialog from orders2 List page.

As always, happy coding, everyone! :-)


inside83
User
Posts: 62

Post by inside83 »

It should not work in v 2018 or I'm doing something wrong?


mobhar
User
Posts: 11660

Post by mobhar »

This code is only for v2021. I am afraid that it does not work for v2018.


dirto
User
Posts: 3

Post by dirto »

sorry, table is missing userlevel and userlevelpermisions


totza2010
User
Posts: 107

Post by totza2010 »

Does this code work for v2023?


mobhar
User
Posts: 11660

Post by mobhar »

Yes, it should work also for v2023 after doing some modification for the code.

This code:
$this->OrderID->ViewValue = "<a href='#' onclick='ew.modalDialogShow({lnk:this,url: \"orders/view/".$this->OrderID->CurrentValue."\",btn: \"ViewBtn\"});'>" . $this->OrderID->ViewValue . "</a>";

should be:
$this->OrderID->ViewValue = "<a href='#' onclick='ew.modalDialogShow({lnk:this,url: \"orders/view/".$this->OrderID->CurrentValue."\",btn: null});'>" . $this->OrderID->ViewValue . "</a>";

In other words, this code:
btn: \"ViewBtn\"

should be:
btn: null

The other code remains the same.


totza2010
User
Posts: 107

Post by totza2010 »

After testing it, it works, but when using Editbtn after editing the data. Content on that page will disappear.


mobhar
User
Posts: 11660

Post by mobhar »

What did you mean by Content on that page will disappear? Did you mean the Modal dialog is closed and back to the List Page of orders2 table?


totza2010
User
Posts: 107

Post by totza2010 »

When you press confirm The page where the button was created turned white with a message that edited successfully. This button is created on the viewing page.


mobhar
User
Posts: 11660

Post by mobhar »

Did you enable Confirm option for Edit Page of customers table? In addition, did you setup Return Page after edit?


totza2010
User
Posts: 107

Post by totza2010 »

in edit page for custom link use confirm. but not set return page.


mobhar
User
Posts: 11660

Post by mobhar »

I cannot reproduce the issue.

I've just tried to enable Confirm option for Edit Page of customers table and then re-generate ALL the script files again.

In the generated web application, everything seems fine, after clicking on Save button, then system will display the Confirm button immediately, and after clicking one Confirm button, then data is saved properly, and Modal dialog is closed as usual.


Post Reply