Page 1 of 1

Set dynamic field default value

Posted: Tue Mar 14, 2017 5:13 pm
by jzb

Dear PHPMaker users,

I have 2 tables :

  • user_settings (with a field called "user_settings_zone")
  • events (with a field called "events_zone")

When user add or edit an event, "events_zone" value must be automatically set as "user_settings_zone" value.

BR

Jam


Re: Set dynamic field default value

Posted: Tue Mar 14, 2017 6:10 pm
by mobhar

Your post is not clear enough. What are the control of both fields? Are they using Combobox (Select) control? If so, then you should populate the data from another lookup table that contains all the timezone records.

You may write jQuery code and put it in "Startup Script" based on change event of the Combobox control to set the value to another field. Please "Server Events and Client Scripts" topic from PHPMaker Help menu for more info.


Re: Set dynamic field default value

Posted: Tue Mar 14, 2017 8:08 pm
by jzb

"user_settings_zone" and "events_zone" are both TEXT.

I cannot use Lookup table because this will affect all records related to "user_settings_zone" value.

Let me clarify. Here is a detailed example :

  1. The User set "user_settings_zone" value to "London"
  2. From this step, all events created or modified by the User will have "events_zone" = "London"
  3. The User set "user_settings_zone" value to "Tokyo"
  4. From this step, all events created or modified by the User will have "events_zone" = "Tokyo"
    etc...

How and Where to set default value in add/edit events form ? "events_zone" value = "user_settings_zone" value

Hope that clarifies


Re: Set dynamic field default value

Posted: Tue Mar 14, 2017 9:50 pm
by mobhar

You may simply use jQuery "keydown" and/or "keyup" to set the same value into another control in the form.

Put that code in "Startup Script" of "Add Page" and/or "Edit Page". Just Goole for the code sample out there.


Re: Set dynamic field default value

Posted: Sat Mar 18, 2017 9:59 pm
by jzb

Thanks for your feedbacks mobhar.

After further investigations, I found that SESSION is the right solution.

  • Server Events > Global > All Pages > User_Validated
    $_SESSION['user_settings_zone'] = $rs['user_settings_zone'];

For user_settings table :

  • Server Events > Table-Specific > Common > Row_Updated
    $_SESSION['user_settings_zone'] = $rs['user_settings_zone'];

For events table :

  • Server Events > Table-Specific > Common > Add/Copy Page > Page_DataRendering
    $this->events_zone->EditValue = $_SESSION['user_settings_zone'];