Cascading Select for existing record not working

Archived from the Xataface Users forum.

dbaron2 — Sun Oct 04, 2009 3:20 am

Hello,

I am using cascading select logic I found elsewhere in the forum (see below) and it works great for new records, but not for existing records. When I pull up an existing record the select box for regions and localities shows ALL regions and ALL localities. Is there a way to trigger the onclick code automatically as part of the page load process? In the meantime I added onfocus event code (below), but it causes the blanking of the previously selected values:

<?

class tables_localities {

function block__after_new_record_form(){

echo «<END

END;

}

function block__after_edit_record_form(){

return $this->block__after_new_record_form();

}

}

?>


Jean — Mon Oct 05, 2009 1:54 am

I used this code that worked for linked select boxes :

Code: Select all
`function block__after_new_record_form(){
//javascript pour lier deux select menus
echo «<END

// $cities is an array with keys city_id and values city_name
// $city_provinces is an array with keys city_id and values province_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 services_options = ‘.$json->encode($services).’;
var services_entites = ‘.$json->encode($services_entites).’;
‘;

echo «</script> END; }`


Jean — Mon Oct 05, 2009 2:11 am

Hello,

You need a END marker after

Jean


dbaron2 — Mon Oct 05, 2009 3:15 am

Whoops! My original message got mangled because I failed to disable HTML for the message.

Here is the actual code:

Code: Select all
`<?
/**
  • A delegate class for the entire application to handle custom handling of
  • some functions such as permissions and preferences.
    */
    class tables_localities {
        function block__after_new_record_form(){
    echo «<END
           
    END;
        }
        function block__after_edit_record_form(){
            return $this->block__after_new_record_form();
        }
    }
    ?>`

shannah — Wed Oct 07, 2009 11:11 am

1.

s. Is there a way to trigger the onclick code automatically as part of the page load process?

Yes. You can use jQuery for this (which is bundled with Xataface in js/jquery.packed.js).

e.g.

Code: Select all
jQuery(document).ready(function($){       // Whatever you put in here happens after the document loads });

2.

? In the meantime I added onfocus event code (below), but it causes the blanking of the previously selected values

You have to make sure that you retain the selected values when you refill the list. I.e. before setting the