Foreign key will not keep value on reload

Talk about foreign keys

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

mposse
Junior
Junior
Posts: 20
Joined: Nov 2nd, '10, 03:45

Foreign key will not keep value on reload

Postby mposse » Apr 28th, '11, 03:18

Hi Admin
I run into a problem I can't find an answer for

I have a foreign key field.
The fk field is set to reload the form and upon that, it queries default values from the db to populate the other fields of the form.
In add mode, I can select an item from the drop down list and when the form reloads, I have a suggested price for the item. That is working fine.

Once the item is submited and you want to edit it, I can't change the item on the dropdown.
You open the dropdown and select a different item and the form is submited with the change, but immediately comes back to the original item.

here is my code

Code: Select all

$ptPrice = 0;
if (($_REQUEST['op_mode'] == 'add' || $_REQUEST['op_mode'] == 'edit') && isset($_REQUEST['riyproducttype']) && ($_REQUEST['riyproducttype'] != "")) {
       $query = "SELECT ptRentalPrice FROM producttype WHERE ptId =" . $_REQUEST['riyproducttype'];
       $rs = db_query($query);
       $row = mysql_fetch_assoc($rs);
       $ptPrice = $row['ptRentalPrice'];
 }
 $producttype = isset($_POST['riyproducttype']) ? $_POST['riyproducttype'] : "";
 if ($debug_mode) echo $producttype;
   
$em_columns = array("tranId"     =>array("header"=>"Id Transaccion", "type"=>"hidden", "req_type"=>"si", "width"=>"210px", "title"=>"", "readonly"=>"true", "maxlength"=>"-1", "default"=>$ordenId, "unique"=>"false", "unique_condition"=>"", "visible"=>"false", "on_js_event"=>""),
      "producttype" =>array("header"=>"Tipo Producto", "type"=>"foreign_key","req_type"=>"ri", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>$producttype, "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
      "prodQtty"   =>array("header"=>"Cantidad", "type"=>"textbox", "req_type"=>"rn", "width"=>"40px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
      "prodPrice" =>array("header"=>"Precio", "type"=>"money", "req_type"=>"rn", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>$ptPrice, "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "sign"=>"$", "sign_place"=>"before", "decimal_places"=>"2", "dec_separator"=>",", "thousands_separator"=>".")
      );
$products->setColumnsInEditMode($em_columns);
   
$foreign_keys = array(
          "producttype"=>array("table"=>"producttype", "field_key"=>"ptId", "field_name"=>"ptDescription", "view_type"=>"dropdownbox", "condition"=>"ptType = 'B'", "on_js_event"=>"onchange='formAction(\"\", \"\", \"".$products->uniquePrefix."\", \"".$products->HTTP_URL."\", \"".$_SERVER['QUERY_STRING']."\", \"get\", \"".$_REQUEST[$products->uniquePrefix.'mode']."\")'"),
     );
     $products->setForeignKeysEdit($foreign_keys);


Any ideas on how to solve this?

administrator
Site Admin
Site Admin
Posts: 5992
Joined: Jan 7th, '09, 23:18
Contact:

Re: Foreign key will not keep value on reload

Postby administrator » Apr 28th, '11, 09:33

In new version FormAction renamed into _dgFormAction

mposse
Junior
Junior
Posts: 20
Joined: Nov 2nd, '10, 03:45

Re: Foreign key will not keep value on reload

Postby mposse » May 9th, '11, 22:03

The version I am using is 6.4.1 and other than this edits, the reload is working fine.
I figured that what happens is that you can't set which is the selected element on the drop down so, on binding, the option selected becomes the value that is loaded from the table.

In my case, when I am in edit mode, I have a dropdown with all the categories of products. When you change the selection, the form is submitted and the new value is sent.
Using that value, I query the database to obtain suggested price for that category.
So far, all the values that I need are correct.
Then the ->bind() method draws the form, and sets the selected option on the dropdown to the value that is on the database.

The solution has been to not reload the page on edit but this cannot be a permanent solution.
As a note, if you are on add mode, then everything works very well.


Return to “Field type: "foreign key"”