DropDown Field values - changing in runtime [message #7678] |
Thu, 10 February 2022 06:51 |
htManager
Messages: 433 Registered: May 2014
|
Senior Member |
|
|
Hi Tony,
I have a DropDown field which works fine. The values of this DropDown field are generated by fields in the same record. These fields are the foreign key of the table where the values come from. After changing the value of these (foreign key) fields with a popup pattern I have to submit and open the record again before I get the new (right) values for the DropDown field.
Can I change the values for the DropDown field in the _cm_popUpReturn() method or somewhere else by calling the _cm_getExtraData() method again? Or is there another way?
For your understanding: In the record are sizes stored depending of dressing type. Shoes (8, 8 1/2, 9, 12, ...) have other sizes as clothes (S, L, XXL, ..). And I want to have the right values for the different types.
|
|
|
|
|
|
Re: DropDown Field values - changing in runtime [message #7682 is a reply to message #7681] |
Wed, 16 February 2022 04:08 |
htManager
Messages: 433 Registered: May 2014
|
Senior Member |
|
|
Sorry, my fault. I didn't explain it right.
I have a foreign (compound) key in my table and I call a popup form to choose an occurence of this foreign table. In _cm_getExtraData() I have the code for filling the dropDown list with the values of a table consisting of the foreign key and another key field with the (detail) values I want.
As far as I understand, the popupReturn event doesn't fire an 'onchange' trigger and that's why the _cm_updateFieldarray() method will not be fired.
Using a dropdown field for a compound key as desribed in FAQ 138 was the last time too difficult for me. But I will try it again.
It is possible to fire an 'onchange' trigger in the _cm_popupReturn() method after filling in the selected values in $fieldarray? Or is there a better solution for this problem?
[Updated on: Wed, 16 February 2022 06:57] Report message to a moderator
|
|
|
|
|
|
|
|
Re: DropDown Field values - changing in runtime [message #7688 is a reply to message #7685] |
Sat, 19 February 2022 04:56 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If the contents of $this->lookup_data['foo_bar'] needs to change depending on a selection which you have made in a dropdown list then you need to rebuild the contents of $array in the _cm_updateFieldarray() method by retrieving data using this selection as an argument.
Any code you have in the _cm_getExtraData() method should not rebuild the contents of $this->lookup_data['foo_bar'] if it already exists.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: DropDown Field values - changing in runtime [message #7692 is a reply to message #7691] |
Sun, 06 March 2022 06:01 |
htManager
Messages: 433 Registered: May 2014
|
Senior Member |
|
|
This is the definition of the column:
$fieldspec['ma_ausruestung_preis_eigenanteil']= array('type' => 'numeric',
'size' => 12,
'precision' => 11,
'scale' => 2,
'minvalue' => 0,
'maxvalue' => 999999999.99,
'default' => '0.00');
If I set $this->fieldspec['ma_ausruestung_preis_eigenanteil']['noedit'] = 'y' in _cm_changeConfig() everything works fine and the value will not be increased.
This is the content of $postarray and $fieldarray in _cm_updateFieldArray()
C:\xampp\htdocs\radicore\htm\classes\orga_mannschaften_konta kte_ausruestung.class.inc:732:
array (size=8)
this is the composed value from the lookup table, existing of the three foreign key values
'gr_art_dropdown' => string '&SCH-DE&D&1' (length=11)
'gr_art_ausr' => string 'S' (length=1)
'ma_ausruestung_ausgabe' => string 'on' (length=2)
'ma_ausruestung_ausgabe_datum' => string '2022-02-19' (length=10)
this is the value which will be increased to 5000.00, 500000.00, 50000000.00, .... each time I change the dropdown field value
'ma_ausruestung_preis_eigenanteil' => string '50.00' (length=5)
'ma_ausruestung_preis_eigenanteil_bezahlt' => string 'on' (length=2)
'ma_ausruestung_preis_eigenanteil_bezahlt_datum' => string '2022-02-19' (length=10)
'ma_ausruestung_trikot_no' => string 'EA' (length=2)
C:\xampp\htdocs\radicore\htm\classes\orga_mannschaften_konta kte_ausruestung.class.inc:733:
array (size=39)
'verbaende_art_id' => string 'LV' (length=2)
'verbaende_kuerzel' => string 'HV S' (length=4)
'vereine_kuerzel' => string 'HVS' (length=3)
'saison_id' => string '2021/2022' (length=9)
'mannschaften_id' => string '2007W' (length=5)
'user_id' => string 'HVS' (length=3)
'user_seq_no' => string '2' (length=1)
'ausruestung_id' => string 'TSHIRT' (length=6)
'ausruestung_anr' => string '2007W-SC-HVS' (length=12)
'rdcaccount_id' => string '7' (length=1)
'ma_ausruestung_kontakt_name' => string 'Alizada' (length=7)
'ma_ausruestung_kontakt_vorname' => string 'Emilia' (length=6)
'ma_ausruestung_marke' => string 'Adidas' (length=6)
'ma_ausruestung_modell' => string 'T 4711' (length=6)
'ma_ausruestung_desc' => string 'T-Shirt Sommercamp 2021 - 2007w' (length=31)
this is the value from the lookup table
'gr_art_dropdown' => string '&KLD-DE&D&1' (length=11)
these are the foreign keys values coming from 'gr_art_dropdown'
'gr_art' => string 'KLD-DE' (length=6)
'gr_art_sub' => string 'D' (length=1)
'gr_art_rdc' => string '1' (length=1)
'gr_art_ausr' => string 'S' (length=1)
'ma_ausruestung_farbe' => string 'rot' (length=3)
'ma_ausruestung_farbnummer' => null
'ma_ausruestung_preis_netto' => string '0.00' (length=4)
'ma_ausruestung_preis_rabatt' => string '0.000' (length=5)
'ma_ausruestung_preis_rabatt_berechnen' => string '0' (length=1)
'ma_ausruestung_preis_mwst' => string '0.00' (length=4)
'ma_ausruestung_preis_mwst_berechnen' => string '0' (length=1)
'ma_ausruestung_preis_brutto' => string '0.00' (length=4)
this is the value which will be increased to 5000.00, 500000.00, 50000000.00, .... each time I change the dropdown field value
'ma_ausruestung_preis_eigenanteil' => string '50.00' (length=5)
'ma_ausruestung_preis_eigenanteil_bezahlt' => string '1' (length=1)
'ma_ausruestung_preis_eigenanteil_bezahlt_datum' => string '2022-02-19' (length=10)
'ma_ausruestung_preis_berechnen' => string '0' (length=1)
'ma_ausruestung_pfad_bild' => null
'ma_ausruestung_pfad_video' => null
'ma_ausruestung_barcode' => null
'ma_ausruestung_trikot_no' => string 'EA' (length=2)
'ma_ausruestung_ausgabe' => string '1' (length=1)
'ma_ausruestung_ausgabe_datum' => string '2022-02-19' (length=10)
'ausruestungs_groesse_art_desc' => string 'Kleider-Größen Damen (EU/DE)' (length=30)
|
|
|
Re: DropDown Field values - changing in runtime [message #7694 is a reply to message #7692] |
Wed, 09 March 2022 04:36 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
According to your sample code the column with the dropdown list is 'ma_ausruestung_preis_eigenanteil', but you have not shown the contents of $this->lookup_data['ma_ausruestung_preis_eigenanteil']. This is an associative array, so I am interested in seeing the keys and the values. You have also not explained how the column 'gr_art_dropdown' fits into the picture. Where is the code which splits your multi-part value into a series of separate values?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
[Updated on: Wed, 09 March 2022 04:37] Report message to a moderator
|
|
|
Re: DropDown Field values - changing in runtime [message #7695 is a reply to message #7694] |
Wed, 09 March 2022 05:09 |
htManager
Messages: 433 Registered: May 2014
|
Senior Member |
|
|
Sorry for my English and how I try to explain what I mean.
The field gr_art_dropdown ('Größe (Art) auswählen')is a field with a dropdown list. It will be filled with the description of the size categories (shoes, cloths, etc.).
The field gr_art_ausr ('Größe') is the field where you can choose the right size of the chosen category.
The field ma_ausruestung_preis_eigenanteil ('Eigenanteil') is the field which holds the part of the total cost which will be payed by the team member.
I added two screen shots: the initial and a changed one. Hopefully you can see what I tried to explain. I added the code of the _cm_getValRep() method of the table from where the values come.
In the screenshot you see in 'Größe (Art) auswählen' the category of the size (shoes, cloth, etc.). And in 'Größe' the selectable values. In 'Eigenanteil' you see the value of the money (50.00, 5000,00).
In the green circle you can see the individual values of the compound foreign key which identify the key for filling the field 'Größe' with the right values.
// ************************************************************ ****************
function _cm_getValRep ($item=null, $where=null, $orderby=null)
// get Value/Representation list as an associative array.
{
$array = array();
switch ($item) {
case 'groessen_art_ausr_kopf' :
// get data from the database
$this->sql_select = 'gr_art, gr_art_sub, rdcaccount_id, ausruestungs_groesse_art_desc';
$this->sql_orderby = 'ausruestungs_groesse_art_desc';
$this->sql_ordery_seq = 'asc';
$data = $this->getData($where);
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$key = '&' . $rowdata['gr_art'] . '&' . $rowdata['gr_art_sub'] . '&' . $rowdata['rdcaccount_id'];
$array[$key] = $rowdata['ausruestungs_groesse_art_desc'];
} // foreach
return $array;
case 'groessen_art_ausr_detail' :
// ermittelt den Primärschlüssel
if (isset($GLOBALS['gr_key_array'])) {
$primary_key_values = $GLOBALS['gr_key_array'];
} else {
$primary_key_values['1'] = $GLOBALS['fieldarray']['gr_art'];
$primary_key_values['2'] = $GLOBALS['fieldarray']['gr_art_sub'];
$primary_key_values['3'] = $GLOBALS['fieldarray']['gr_art_rdc'];
}
// get data from the database
$this->sql_select = 'orga_groessen_ausr_detail.gr_art_ausr, orga_groessen_ausr_detail.argroesse_desc';
$this->sql_from = "orga_groessen_ausr " .
" LEFT JOIN orga_groessen_ausr_detail ON (" .
"orga_groessen_ausr_detail.gr_art = orga_groessen_ausr.gr_art AND " .
"orga_groessen_ausr_detail.gr_art_sub = orga_groessen_ausr.gr_art_sub AND " .
"orga_groessen_ausr_detail.rdcaccount_id = orga_groessen_ausr.rdcaccount_id)";
$this->sql_orderby = 'argroesse_desc';
$this->sql_ordery_seq = 'asc';
$where = "gr_art = '{$primary_key_values['1']}' AND " .
"orga_groessen_ausr_detail.gr_art_sub = '{$primary_key_values['2']}' AND " .
"orga_groessen_ausr_detail.rdcaccount_id = '{$primary_key_values['3']}'";
$data = $this->getData($where);
// convert each row into 'id=desc' in the output array
foreach ($data as $row => $rowdata) {
$rowvalues = array_values($rowdata);
$array[$rowvalues[0]] = $rowvalues[0] . ' - ' . $rowvalues[1];
} // foreach
return $array;
} // switch
return $array;
} // _cm_getValRep
[Updated on: Wed, 09 March 2022 09:03] Report message to a moderator
|
|
|
Re: DropDown Field values - changing in runtime [message #7696 is a reply to message #7695] |
Fri, 11 March 2022 06:03 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I do not want to see how you construct the contents of each dropdown list in $this->lookup_data['...'], I want to see the actual contents. Then I want to see the code which is executed whenever you change a value in one of the dropdown lists in the screen. I want to see how you split the compound key into its component parts and then what you do with each of those parts.
You originally described your problem as follows: Quote:If I change the value in the dropdown list the value of a numeric field will be increased by a factor of 100. From 50,00 to 5000,00 and so on
Are you saying that your code increases the value of this numeric field by a factor of 100 when it should not? You need to show the the code which you are using and highlight the place where it is producing the wrong result.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
Re: DropDown Field values - changing in runtime [message #7697 is a reply to message #7696] |
Fri, 11 March 2022 09:53 |
htManager
Messages: 433 Registered: May 2014
|
Senior Member |
|
|
I split the compound key into its component parts in _cm_updateFieldArray() with the following code:
$str_gr_art = $postarray['gr_art_dropdown'];
if (isset($postarray['gr_art_dropdown'])) {
$gr_key_array = explode('&', $str_gr_art);
// weist die Daten $GLOBALS zu
$GLOBALS['gr_key_array'] = $gr_key_array;
// liest die Schlüsselwerte der ausgewählten Größe ein
$fieldarray['gr_art'] = $gr_key_array[1];
$fieldarray['gr_art_sub'] = $gr_key_array[2];
$fieldarray['gr_art_rdc'] = $gr_key_array[3];
// ermittelt die Größen-Werte aus orga_groessen_ausr_detail
$dbobject =& RDCsingleton::getInstance('orga_groessen_ausr_detail'); // Instanz für Lookup-Tabelle
$dbobject->sql_select = 'gr_art_ausr, argroesse_desc';
$where = "gr_art='{$fieldarray['gr_art']}' AND " .
"gr_art_sub='{$fieldarray['gr_art_sub']}' AND " .
"rdcaccount_id='{$fieldarray['gr_art_rdc']}'";
// sortiert die Daten
$dbobject->sql_orderby = 'argroesse_desc';
$data = $dbobject->getData ($where);
// weist die Werte der Lookup-Variablen zu
foreach ($data as $row => $rowdata) {
$rowvalues = array_values($rowdata);
$array[$rowvalues[0]] = $rowvalues[0] . ' - ' . $rowvalues[1];
} // foreach
}
But the code is in my opinion not the problem. The numeric field has the same behaviour even if I set the above code in /* */
If I change the value of the numeric field before changing the dropdown field from 50,00 to 50,0, the numeric field will be increased to 500,00. If I change the value to 5 the value will not be increased but changed to 5,00. 5,0000 will be changed to 50.0000,00 and so on.
Changing the value of the numeric field to 5.00 (. instead of ,) increases the value by the factor of 100 and so on..
If I delete the code "$this->fieldspec['gr_art_dropdown']['javascript'] = array('onchange' => 'this.form.submit();');" in _cm_changeConfig(), nothing happens, the numeric field doesn't change the value.
[Updated on: Sat, 12 March 2022 09:18] Report message to a moderator
|
|
|
Re: DropDown Field values - changing in runtime [message #7698 is a reply to message #7697] |
Mon, 14 March 2022 05:41 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You really need to learn how to debug your code. If you don't have an IDE with a symbolic debugger then you should put some echo statements into you code to display what values are appearing in your variables.
I spotted one mistake straight away - after you unpack the string into an array with $gr_key_array = explode('&', $str_gr_art); you reference the three parts with indexes [1], [2] and [3]. This is wrong as the array starts with index [0].
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: DropDown Field values - changing in runtime [message #7700 is a reply to message #7699] |
Wed, 16 March 2022 05:48 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
The only way to get an empty string in array[0] is if your string contains the '&' delimiter at the very start, as in '&one&two&three' when the normal practice would be to use 'one&two&three'.
When debugging a problem the first place to look is always a custom method which contains code which you have written. You need to look at the input values to see if they are correct and then the output values to see if they are correct. You need to identify the code which is producing the wrong result, then examine the execution of that code line by line with your debugger to see exactly where it is producing the wrong result.
You keep trying to describe what is going wrong, but unless I can run the actual code which you are using and duplicate the error I will never be able to fix it..
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: DropDown Field values - changing in runtime [message #7702 is a reply to message #7701] |
Thu, 24 March 2022 06:54 |
AJM
Messages: 2367 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
All decimal values, both within PHP and the database, use the same format - decimal point is '.' with no thousands separator. This means that five thousand is held as '5000.00'. When displayed this is converted to '5,000.00' for the UK and '5.000,00' for Germany. When using dropdown lists to provide choices for the user this list is an array of entries with a key and a value. The key is used internally in the code while the value can change according to the user's language. The framework does not automatically convert any decimal values used as keys between internal and external format for the simple reason that keys are never displayed to the user, only the values. I cannot see why the value in $fieldarray['ma_ausruestung_preis_eigenanteil']is being changed from '50.00' to '5000' as I am unable to duplicate this problem on my PC as you have yet to provide me with the actual code that you are using. All you keep doing is provide descriptions of the code which is not enough. I need to see the exact contents of the dropdown list, not a description of how you build it.
If you have spotted that the value is being changed somewhere after the call to _cm_updateFieldArray() and before the call to _cm_commonValidation() then that is where you need to step through with your debugger to see precisely where the value is being changed.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|