Like many others I want 1 select list dependent on another select list. In other words when someone selects something in a select list the other select list is populated based on that selection.
I've seen several threads on this subject and I've tried to make it work but I get all values possible in the second select instead of just the ones that should be there based on the first selection.
I did see this post by Steve and I was wondering if it has been implemented yet since it was version 0.7 that this post was made.
http://xataface.com/forum/viewtopic.php?p=20317#p20317
I think what's stumping me is the example code has "slave" and "master" sprinkled through and I believe I need to substitute my actual names but I don't know where. I'm specifically looking at this example.
http://xataface.com/wiki/index.php?-act ... -mode=list
Can anyone help me understand what has to be replaced with my fields there?
Thanks
Don
Edit: Here's what my 3 files currently look like.
fields.ini
- Code: Select all
[mwa_number]
widget:label= "MWA Number"
widget:type = select
vocabulary = mwa_number
[part_number]
widget:label="Part Number"
widget:type = select
filter=on
vocabulary = part_number
valuelist.ini
- Code: Select all
[part_number]
__sql__ = "SELECT part_number, part_number, mwa_number FROM mwa_parts"
[mwa_number]
__sql__ = "SELECT mwa_number, mwa_number FROM mwa"
transactions.php
- Code: Select all
<?php
class tables_transactions {
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']);
$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
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;
slave_field.options.length = 0;
var index = 0;
for ( slave_id in slaves_options){
if ( selected_master == slaves_master[slave_id] ){
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();
}
}
?>