Dynamic_select_boxes Questions

Archived from the Xataface Users forum.

fabien_ecl — Thu Nov 11, 2010 1:03 am

Hi,

I’m trying to implement the dynamic select boxes according to this page

Yet, I have some differences in the way master and slaves are connected : indeed, I do not have the master id in my slave table but the master name… so I update the valuelist.ini

Code: Select all
`;valuelist for the slave
[slaves_list]
sql = “select slave_id, slave_name, master_name from slaves”

; valuelist for the masters
[masters_list]
sql = “select master_id,master_name from masters”`

After I implement the javascript code in the delegate class but it does not make what I want. I tried to modify the javascript but I’m really not proficient in java

Code: Select all
function block__after_new_record_form(){ echo <<<END <script language="javascript"><!-- var slave_field= document.getElementById('slave'); var master_field = document.getElementById('master'); END; // Let's get all the slaves available. $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $table =& Dataface_Table::loadTable($query['-table']);

Right here I understand so it’s OK

Code: Select all
`$slaves = $table->getValuelist(‘slaves_list’);
$slave_masters = $table->getValuelist(‘slaves_list__meta’);
// Note that the slaves_list__meta valuelist is automatically created
// because we had three columns in the slaves valuelist.
// The first and third columns effectively create a 2nd valuelist
// named ‘slaves_list__meta’

// $slaves is an array with keys slave_id and values slave_name
// slave_masters is an array with keys slave_id and values master_id`

From there I’m lost : in fact I don’t understand what I have in slaves (two fields slave_id and slave_name?). In slaves_masters, I have slaves_id and master_name (according to my example)?

Code: Select all
`import(‘Services/JSON.php’);
$json =& new Services_JSON(); // A JSON encoder to allow us to easily
// convert PHP arrays to javascript arrays.
echo ‘
var slaves_options = ‘.$json->encode($slaves).’;
var slaves_master = ‘.$json->encode($slave_masters).’;
‘;

echo «<END
master_field.onchange = function(){
var selected_master = master_field.options[master_field.selectedIndex].value;`

Here I’m really in the space Is there a link where I can find documentation about that (_field and .options significance)?

Code: Select all
slave_field.options.length = 0; var index = 0; for ( slave_id in slaves_options){ if ( selected_master == slaves_master[slave_id] ){

It’s here I suppose that I have to make my modification since I’m using master_name in my slave table and not master_id but selected_master is the id of the master not the name?

Code: Select all
`slave_field.options[index++] = new Option(slaves_options[slave_id], slave_id);
}
}
};
//–></script>
END;
}

// Also place this javascript after an edit record form…
function block__after_edit_record_form(){
return $this->block__after_new_record_form();
}`

By the way, I didn’t say it yet but Xataface is really a wonderful tool It necessitates a little time to be familiar with syntax and the way wu use tables we get from sql but after it’s just too easy. You really made a great job


fabien_ecl — Sat Nov 20, 2010 5:47 am

OK I resolve the problem by myself. there were tow errors : one a the beginning

Code: Select all
var slave_field= document.getElementById('slave'); var master_field = document.getElementById('master');

I had there to replace slave and master by the right values.

The second one was at this line :

Code: Select all
if ( selected_master == slaves_master[slave_id] ){

where I had to insert the value of the master I get back from the master sql table.

I still have a problem : when I try to update (not to edit) a record, I don’t have a dynamically generated slaves value from the existing master one. Anyone can help?
By the way, the more i practice Xataface, the more I love it


fabien_ecl — Wed Nov 24, 2010 12:22 am

fabien_ecl wrote:
I still have a problem : when I try to update (not to edit) a record, I don’t have a dynamically generated slaves value from the existing master one. Anyone can help?

Il will permit myself to up the post… I still have no solution for dynamic selected box and update form.
And I have a question : if i look into the table I update dynamically, the fields do not contain master value and name value but master_id and slave_id whereas xataface display the right value corresponding to the master_id and the right slave name according to the slave_id it stores in the table. Where can I find the correspondance table or the mechanism xataface uses doing that?