Client Scripts for addopt page

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
FelipeRau12
User
Posts: 45

Client Scripts for addopt page

Post by FelipeRau12 »

<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");

</script>

The question is, from which section of Client Scripts in PHPMaker this code could be added?

where inside the project I can include the java script for the addpt file?

Thanks


mobhar
User
Posts: 11703

Post by mobhar »

Currently it is not available, yet. I just tried to add it from Add Page, but it will not be added into the generated *addopt.php" file. It seems you need to add it manually into the generated script file. Please correct me if I'm wrong.


Webmaster
User
Posts: 9427

Post by Webmaster »

Note that Add Option dialog is also a Bootstrap modal dialog, you can always use modal dialog events, e.g.

$("#ewAddOptDialog").on("shown.bs.modal", function (e) {
// do something...
});

Also read: https://getbootstrap.com/docs/3.3/javascript/#modals


mobhar
User
Posts: 11703

Post by mobhar »

The next question is, how do we define the Javascript code for the "Startup Script" that belongs to the addopt page via our PHPMaker project, because we did not see any addopt part under the "Client Scripts" section?


Webmaster
User
Posts: 9427

Post by Webmaster »

The modal dialog events should be placed in the global Startup Script. Alternatively, if you want to place it in Add/Edit page for a table only, you can use Startup Script for that page, but you need to do it on page load, e.g.

$(function() {
$("#ewAddOptDialog").on("shown.bs.modal", function (e) {
// do something...
});
});

This also applies to other modal dialogs, including modal dialog for Add/Edit/etc. pages, modal lookup dialog and the Export to Email dialog. View HTML source in browser to find the id of the dialogs.


mobhar
User
Posts: 11703

Post by mobhar »

Thank you for your explanation. It does make sense.

I just still wonder, if in the generated *addopt.php page there is Startup Script added/generated there, how do we define it from the PHPMaker project side?

In other words, if we cannot add it the code from inside PHPMaker project, that should be generated inside the generated *addopt.php file, then PHPMaker should not generate the Startup Script section into *addopt.php file. Just my two cents.


sangnandar
User
Posts: 980

Post by sangnandar »

My setup:
tableA
fields:

  • fieldA, a TEXT field.
  • fieldX, a lookup field to tableX, with allow add enabled, also has TEXT field named fieldA.

I add this Startup Script in tableAedit.php :

$("#x_fieldA").focus();
$(function() {
$("#ewAddOptDialog").on("shown.bs.modal", function (e) {
$("#ewAddOptDialog").find("#x_fieldA").hide(); // it works.
});
});

Then, when I changed .hide() to .focus() it doesn't work, console gives no error.
$("#ewAddOptDialog").find("#x_fieldA").focus(); // it doesn't work.

Note:
Adding this
$("#x_fieldA").focus();
manually in tableXaddopt.php Startup Script also does work.

Please help.


arbei
User
Posts: 9358

Post by arbei »

I tried below and it focus successfully.

$("#ewAddOptDialog").on("shown.bs.modal", function(e){
$(function(){
$(this).find("input#x_<Field>").focus();
});
});


sangnandar
User
Posts: 980

Post by sangnandar »

Yes, it works.
Thanks.


Post Reply