I'm experience a big problem in latest versions of D6 (I've tested it in D6.3 and D6.4). I have searched and it's not new... it's related to the new menu system?? Look at http://drupal.org/node/272821
The thing is when you write a form that involves some JS, a lot of warnings of the type "warning: Invalid argument supplied for foreach() in F:\xampplite\htdocs\d2\includes\menu.inc on line 258." become to appear...
For you to test it, I've written a "demo" of the behaviour I want to write, but by the way it's affecting to other modules behaviour like ActiveSelect (there's a port to D6 with the same issue)
The example is simply a form with 2 selects, parent and children that when you change the value in parent, the children does an ajax request to modify its values:
test.info
; $Id$
name = "Test"
description = "Test"
core = 6.x
php = 5.1
test.module
function test_menu() {
$items = array();
$items["test/form"] = array(
'title' => t('Test form'),
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('buildTestForm'),
'access arguments' => TRUE,
);
$items["test/json/%"] = array(
'type' => MENU_CALLBACK,
'page callback' => 'getJSON',
'page arguments' => array(2),
'access arguments' => TRUE,
);
return $items;
}
function getJSON($parentKey) {
if ($parentKey === "keySoccer") {
$terms = array(
"Messi",
"Ronaldinho",
);
} else if ($parentKey === "keyBasketball") {
$terms = array(
"Jordan",
"M. Johnson",
);
}
print drupal_to_js($terms);
exit();
}
function buildTestForm() {
drupal_add_js(drupal_get_path('module', 'test') .'/test.js');
$form['parent'] = array(
'#type' => 'select',
'#title' => t('Parent'),
'#options' => array(
"keySoccer" => "Soccer",
"keyBasketball" => "Basketball",
),
);
$form['child'] = array(
'#type' => 'select',
'#title' => t('Child'),
'#options' => array(),
'#DANGEROUS_SKIP_CHECK'=>true,
);
return $form;
}
test.js
if (Drupal.jsEnabled) {
function searchSubTerm(parentSelect, targetSelect) {
$.getJSON( "/XXX/test/json/"+parentSelect.val(), {id: $(this).val(), ajax: 'true'}, function(j) { //Check the url to your menu!!!
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option>' + j[i] + '</option>';
}
targetSelect.html(options);
})
}
$(document).ready( function() {
$(function() {
$("#edit-parent").change(function() {
searchSubTerm($("#edit-parent"),$("#edit-child"));
});
});
});
}
This is an example of the behaviour I want, the "real" thing is to get to work a navigation across the terms of a certain vocabulary for a custom search of a custom node type... for example in a node type CAR, a block to search them by the fuel type, or make/model/version, etc
Do anyone know what happens with menu system? Is it a bug? What can I do? I've spent a lot of hours looking for a solution...
Thank you very much
Juan Arias
Spain
Comments
I've developed a Drupal 5
I've developed a Drupal 5 version and it works perfectly... is something wrong with the menu system in D6????
If anyone is interested let me know and I'll post it
SOLVED!!! I'm a bit fool...
SOLVED!!!
I'm a bit fool... the mistake is that in D6 "access arguments" is an ARRAY!!! so simply changing
'access arguments' => array(TRUE),
the thing is done...
Well, at least take this as an example of doing some ajax to link the result of two combos, by the way, I'll post in a while a D6 port of the ActiveSelect project that does this in a 'more elegant way' so if you want to have a look at it, I'll correct the D6 port and I'll upload it to the support requests of the project so the mantainer can check it
Greetings
Juan Arias
Spain