This topic is locked
[SOLVED]

 Dropdown menu options

2/28/2012 10:28:29 AM
PHPRunner General questions
F
Francesco_5000 author

Hi,
i want to obtain a certain behaviour during the edit of a record. The concept is this: i have a lighting system, it can be switched on, or it can be switched off, or it can be only partially switched on (i.e. some light bulbs are switched on and the other light bulbs are switched off).
So, if the plant initially was On, during the edit, i want to see only these options: "Off" ; "Partially". I'm wondering if it's possible to obtain this behaviour with something like this: http://xlinesoft.com/phprunner/docs/add_dropdown_list_box_with_values_for_search.htm . To me is quite easy to manipulate a query , the difficult part is to integrate it in a PHPRUNNER page.

Admin 2/28/2012

Sorry, it's not clear if you are talking about the Edit page or about adding dropdown to the list page as per this example: http://xlinesoft.com/phprunner/docs/add_dropdown_list_box_with_values_for_search.htm
Please elaborate.

F
Francesco_5000 author 2/28/2012



Sorry, it's not clear if you are talking about the Edit page or about adding dropdown to the list page as per this example: http://xlinesoft.com/phprunner/docs/add_dropdown_list_box_with_values_for_search.htm
Please elaborate.


i'm talking about the edit page, the link present in my previous post was an example of the behaviour that i want to obtain, that is a dropdown menu with only certain options.

Admin 2/28/2012

When you setup a dropdown box in PHPRunner add a WHERE clause to filter options i.e.

fieldname = 'Off' or fieldname = 'Partially'


Replace fieldname with the actual field name that stores options.

F
Francesco_5000 author 2/29/2012



When you setup a dropdown box in PHPRunner add a WHERE clause to filter options i.e.

fieldname = 'Off' or fieldname = 'Partially'


Replace fieldname with the actual field name that stores options.

F
Francesco_5000 author 2/29/2012



When you setup a dropdown box in PHPRunner add a WHERE clause to filter options i.e.

fieldname = 'Off' or fieldname = 'Partially'


Replace fieldname with the actual field name that stores options.


I want to do something like this:



SELECT *

FROM lighting_system_state

WHERE state <> actual_state


i.e. I want to use that query to populate the options in the dropdown menu, in this way, when I have to edit the record, the actual state is not present. My question is: "How to retrieve the actual state of the lighting system?". I'm wondering if I can use a variable $actual_state obtained from a different query (present for instance in an event) into the where clause of the dropdown box in PHPRunner.
If I want to use a list-of-values instead of a lookup-table, I think that I need to use a javascript onload event, but for me the problem is always to retrieve the actual state of the lighting system, because I don't want to see it in the dropdown menu.

C
cgphp 2/29/2012

You can create a custom field: http://xlinesoft.com/phprunner/docs/add_custom_field_to_form.htm
In the visual editor enter a template variable like this:

{$dropdown_lighting_state}


In the "Before display" event populate the dropdown:

$str = "<select name='lighting_state' id='lighting_state'>";

$rs = CustomQuery("SELECT * FROM lighting_system_state WHERE state <> actual_state"); // change the query to fit your needs

while($record = db_fetch_array($rs))

{

$str .= "<option value='".$record['val_field_here']."'>".$record['val_field_here']."</option>";

}

$str.= "</select>";
$xt->assign("dropdown_lighting_state",$str);


In the "Javascript onload" event enter this code:

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

var val = $("#lighting_state").val();

formObj.baseParams['lighting_state'] = val;

});


In any event like "Before record edit" or "Before process" use $_REQUEST["lighting_state"] to access the custom field value.

F
Francesco_5000 author 3/6/2012

i've a question... if I create a custom field for the edit page then I find the same field also in the add page?



You can create a custom field: http://xlinesoft.com/phprunner/docs/add_custom_field_to_form.htm
In the visual editor enter a template variable like this:

{$dropdown_lighting_state}


In the "Before display" event populate the dropdown:

$str = "<select name='lighting_state' id='lighting_state'>";

$rs = CustomQuery("SELECT * FROM lighting_system_state WHERE state <> actual_state"); // change the query to fit your needs

while($record = db_fetch_array($rs))

{

$str .= "<option value='".$record['val_field_here']."'>".$record['val_field_here']."</option>";

}

$str.= "</select>";
$xt->assign("dropdown_lighting_state",$str);


In the "Javascript onload" event enter this code:

this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

var val = $("#lighting_state").val();

formObj.baseParams['lighting_state'] = val;

});


In any event like "Before record edit" or "Before process" use $_REQUEST["lighting_state"] to access the custom field value.

C
cgphp 3/6/2012

No, you have to manually create the field for the add page.