Page 1 of 1

Open modal window through get variable

Posted: Sat Mar 25, 2023 2:48 pm
by mrlux

May I can open modal window through get or session variable?

There is page1 view with id=5 in the modal window, which has a button to go to page2 edit, after which you need to return to page1 view with id=5 in the modal window.

I'm using 2023, by default, there is a return to page 2 listing. I use a variable in the session that remembers the path to the page of the modal window, so that later it can be displayed through List Page -> Page_Redirecting

if (isset($_SESSION["path"])) {
    $url = $_SESSION["path"];
}

I can go back to the normal page, but I need to go back and automatically open the modal that I was in at the start.

I am on one page, I click on the link and go to edit another table linked by ID number. After that, I must return not to the listing, but to the beginning. I can do this, but I need to return to the modal window, and not to the normal page.


Re: Open modal window through get variable

Posted: Sat Mar 25, 2023 9:37 pm
by mobhar

You may simply try:

  1. Make sure you have already enabled Modal dialog option under Table setup -> Table Options -> View Page and Edit Page of your users table,
  2. Make sure you have already selected View Page under Table setup -> Table Options -> Return Pages -> After edit,
  3. Re-generate ALL the script files, and try again.

Re: Open modal window through get variable

Posted: Sat Mar 25, 2023 10:00 pm
by mrlux
  1. Naturally, the modal window function is enabled and they are displayed in modal windows.
  2. This function allows you to return to adding, deleting, editing, listing and viewing only the table on which the action occurs. I need to move to another table. I did it in a normal window, but I can't go to the modal window.

I use

if (isset($_SESSION["path"])) {
    $url = $_SESSION["path"].'&modal=1';
}

but this not opens a modal window, just a normal one.

Custom View Tag:

<a data-ew-action="modal" data-ajax="false" data-url="leftovers?id=<?php
echo urlencode(CurrentPage()->item_name_id->CurrentValue) ?>"><?php
echo CurrentPage()->item_name_id->ViewValue ?></a>

This will take you to the post page, which you can edit. But after that you will be returned to the list, viewing, adding, deleting or editing a table with these records. And I need to return to another table. And I successfully do this, but this opens a full normal page, and I need the page to open in a modal window.

Scheme: page 1 -> page 2 (modal) -> edit page 3 -> return page 2 (MODAL)

page 2 (modal) is not tied to any table and is a synthetic page for the convenience of working and merging several tables.

page 3 linked to edit table


Re: Open modal window through get variable

Posted: Sun Mar 26, 2023 2:49 pm
by arbei

Note that the modal dialog returns to where it is opened. If you open the modal Edit dialog in the List page, it returns to the List page. If you open the modal Edit dialog in modal View page of the same table, it returns to the modal View page after editing. It is the default behavior, there should be no need to add server events or set Return Page.

However, you mentioned "custom page" (e.g. "leftovers" does not sound like a regular Edit page of a table). It won't work in Custom Files or other custom pages, because there is no List/View/Edit Page in a custom file/page like normal tables.

It won't work either if you open Table2's modal Edit page from Table1's modal View page. To return to Table1's modal View page, the Table2's Edit page should return JSON response after editing like Table1's Edit page, e.g.

{ url: "Table1View/xxx", modal: true }

You may try to use Row_Updated server event of the Edit page to call the page's terminate() method and then use WriteJson() to write the custom JSON response.


Re: Open modal window through get variable

Posted: Wed Mar 29, 2023 5:06 am
by mrlux

Row Updated event:

if (isset($_SESSION["path"])) {
    $url = $_SESSION["path"];
    $this->terminate($url.$rsnew["id"]);
    WriteJson(["url" => $url.$rsnew["id"], "modal" => "true"]);
}

There is a correct return to the normal page, but not to the modal window.

if (isset($_SESSION["path"])) {
    $url = $_SESSION["path"];
    WriteJson(["url" => $url.$rsnew["id"], "modal" => "true"]);
$this->terminate();
}

This also does not work and only displays a message on the screen: {"url":"leftovers?id=3","modal":"true"}


Re: Open modal window through get variable

Posted: Wed Mar 29, 2023 1:02 pm
by mobhar

You may try:

if (isset($SESSION["path"])) {
    $url = $SESSION["path"];
    WriteJson([
        "url" => $url.$rsnew["id"],
        "caption" => "View " . $rsnew["id"],
        "view" => true,
        "modal" => true
    ]);
    $this->terminate();
}

Re: Open modal window through get variable

Posted: Wed Mar 29, 2023 10:11 pm
by mrlux

It also doesn't work. I am getting a blank page with data printed on it:

{"url":"leftovers?id=5","caption":"View 5","view":true,"modal":true}

Perhaps something else needs to be included or added to the code.

I check my code with F12.

Headers: Status Code: 200 OK

Preview: {url: "leftovers?id=3", caption: "View 3", view: true, modal: true}
caption: "View 3"
modal: true
url: "leftovers?id=3"
view: true

Response: {"url":"leftovers?id=3","caption":"View 3","view":true,"modal":true}

Content-Type: application/json; charset=utf-8


Re: Open modal window through get variable

Posted: Thu Mar 30, 2023 3:11 pm
by mobhar

It seems leftovers is a Custom File. Is that right? If so, then that's the cause why it does not work.

arbei wrote:

However, you mentioned "custom page" (e.g. "leftovers" does not sound like a regular Edit page of a table). It won't work in Custom Files or other custom pages, because there is no List/View/Edit Page in a custom file/page like normal tables.


Re: Open modal window through get variable

Posted: Sat Apr 01, 2023 12:56 am
by mrlux

I have tried going back to both the user page and the page that is linked to the real table. But it doesn't work.

{"url":"orderstatus?id=6","caption":"View 6","view":true,"modal":true} - This is no longer a custom page


Re: Open modal window through get variable

Posted: Sat Apr 01, 2023 8:53 am
by mobhar

Are you sure orderstatus?id=6 is a valid URL? Have you tried to access this page without Modal dialog? Does it work?

If your table is orderstatus, then the View page should be orderstatusview/6.


Re: Open modal window through get variable

Posted: Sun Apr 02, 2023 3:21 pm
by mrlux

I use it for a modal dialog, but the page does not open, but only appears

{"url":"orderstatusview?id=6","caption":"View 6","view":true,"modal":true}

it link opens simple page with view, but without modal


Re: Open modal window through get variable

Posted: Mon Apr 03, 2023 9:16 pm
by mobhar

How about this?

if (isset($SESSION["path"])) {
    $url = $SESSION["path"];
    WriteJson([
        "url" => "orderstatusview/6",
        "caption" => "View " . $rsnew["id"],
        "view" => true,
        "modal" => true
    ]);
    $this->terminate();
}

Does it open the page by using that hardcoded URL inside the Modal dialog?


Re: Open modal window through get variable

Posted: Mon Apr 03, 2023 10:29 pm
by mrlux

No, it doesn't, because there is an extra backslash.

{"url":"orderstatusview\/6","caption":"View 6","view":true,"modal":true}

I've tried various functions but they don't remove the backslash. It is not clear where he comes from.


Re: Open modal window through get variable

Posted: Tue Apr 04, 2023 8:15 am
by arbei

It is only an escaped character in JSON string. When you wrote your response, you provided an array, which needed to be converted to JSON by json_encode(). The escaped character is correct, JavaScript will decode it when it reads JSON response. Problem of your case is that, the response is handled as string, not JSON, even you said that the content type is application/json.

If your site is generated by an earilier version of v2023, you better update to the latest version (v2023.11 as of today), generate the ew.js again, and press Ctrl + F5 in your browser to make sure the latest *.js are loaded.

Also, try to Debug JavaScript and find out how your HTTP response is handled.


Re: Open modal window through get variable

Posted: Tue Apr 04, 2023 8:15 pm
by mrlux

I have v2023.11, updated all files but nothing changed

if (isset($_SESSION["path"])) {
    $url = $_SESSION["path"];
    json_encode(WriteJson([
        "url" => $url.$rsnew["id"],
        "caption" => "View " . $rsnew["id"],
        "view" => true,
        "modal" => true
    ]));
    $this->terminate();
}

That doesn't work either. Apparently something else needs to be done.

{"url":"orderstatusview\/7","caption":"View 7","view":true,"modal":true}


Re: Open modal window through get variable

Posted: Tue Apr 04, 2023 9:23 pm
by arbei

arbei wrote:

The escaped character is correct, JavaScript will decode it when it reads JSON response.

You do not need to handle that. Your code is json_encode(WriteJson(..)) is wrong.

As suggested, the problem is elsewhere, you should try to find it out in the F12 -> Source panel in your browser instead:

Problem of your case is that, the response is handled as string, not JSON, even you said that the content type is application/json.

As said, you should

try to Debug JavaScript and find out how your HTTP response is handled.

(Not just checking JavaScript error in F12 -> Network. It is not a JavaScript runtime error, you need to find out why the HTTP response is not handled as JSON.)


Re: Open modal window through get variable

Posted: Wed Apr 05, 2023 5:47 pm
by mrlux

Even if I don't use " / ", I still get this message {"url":"orderstatusview?id=5","caption":"View 5","view":true,"modal":true}

Although if you paste "orderstatusview?id=5" into the address bar, the page opens

$_SESSION["path"] = 'orderstatusview?id='.$this->id->CurrentValue;

if (isset($_SESSION["path"])) {
    $url = $_SESSION["path"];
    WriteJson([
        "url" => $url.$rsnew["id"],
        "caption" => "View " . $rsnew["id"],
        "view" => true,
        "modal" => true
    ]);
    $this->terminate();
}

F12 -> Sources -> No mistakes

What is the problem?