Set Value in List/View page

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

Set Value in List/View page

Post by sangnandar »

I have a table with only 2 fields
dateofbirth --> field from database
age --> custom field

I have JS function to calculate age based on dateofbirth.
I need to display the result in List/View page.
Where should I put my function? Within "Server Events and Client Scripts"? Where?

Thanks.

PS: I know I can write the age function with MySQL and call it in Field-Setup-->Expression, but I prefer to do it with JS to minimize DB performance.


mobhar
User
Posts: 11703

Post by mobhar »

  • Client Scripts -> Table-Specific -> List Page -> Startup Script
  • Client Scripts -> Table-Specific -> View Page -> Startup Script

sangnandar
User
Posts: 980

Post by sangnandar »

How to set the value to the field?
I mean, something like $this->(fieldname)->EditValue = "somevalue" ; in edit page, but to work in List/View page.

Thanks.


mobhar
User
Posts: 11703

Post by mobhar »

Please note that in List Page, there is no Form in that page, except for Search, Pager, Grid-Add, and Grid-Edit form.

If you want to change the current value in main table of List Page other than those forms above, then you may simply use ViewValue property that belongs to the field and put it in "Row_Rendered" server event, for example:

$this->MyFieldname->ViewValue = "something";


sangnandar
User
Posts: 980

Post by sangnandar »

I can't do this in Row_Rendered:

function Row_Rendered() {
var abc = "something" ;
$this->MyField->ViewValue = abc ;
}

What I want to achieve is this:

var bod = dateofbirth;
var date = new Date() ;
(some calculation resulting XXX)
and set XXX to age
$this->age->ViewValue = XXX ;

Thanks.


mobhar
User
Posts: 11703

Post by mobhar »

Try:

function Row_Rendered() {
$abc = "something";
$this->MyField->ViewValue = $abc;
}


sangnandar
User
Posts: 980

Post by sangnandar »

Great, it works.

How to call nested function within Row_Rendered?
I try this but fail:

function Row_Rendered() {
function abc() {
return 123;
}
$this->MyField->ViewValue = abc();
}

Fatal error: Cannot redeclare abc() (previously declared in C:\...\ageinfo.php:911) in C:\...\ageinfo.php on line 910

Thanks.


mobhar
User
Posts: 11703

Post by mobhar »

As the error message said, you cannot create/redeclare a new function inside another existing function. The solution for your case, simply put your own global function in "Global Code", and then just call your own function from that "Row_Rendered" server event.

Please read "Server Events and Client Scripts" topic from PHPMaker Help menu for more information.


sangnandar
User
Posts: 980

Post by sangnandar »

That's it, thanks.
I put my function on Server Events-->Global-->All Pages-->Global Code , call it in Server Events-->Table Specific-->Common-->Row_Rendered, and it works as expected.


Post Reply