Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As I promised in a forum post, my port to D6 is fully working, integrating a couple of patchs for correcting for IE7 and one or two bugs... I have it working great in a web Im working at so I post for you to check and test...
activeselect.info
; $Id: activeselect.info,v 1.1 2007/01/05 15:57:53 jaza Exp $
name = Active select
description = Defines the activeselect form element, which allows modules to have AJAX-enabled select boxes.
; Information added by drupal.org packaging script on 2007-01-05
version = VERSION
core = 6.x
project = "activeselect"
activeselect.module
<?php
// $Id: activeselect.module,v 1.9 2007/01/05 15:57:53 jaza Exp $
/**
* @file
* Defines the activeselect form element, which allows modules to have
* AJAX-enabled select boxes.
*/
/**
* Implementation of hook_help().
*/
function activeselect_help($section) {
switch ($section) {
case 'admin/help#activeselect':
return '<p>'. t('The activeselect module defines the activeselect form element. An activeselect element is the same as a regular select element, except that when the user selects a new option (or set of options), a different select element (the target element) gets its list updated. This is done using AJAX, and it is designed to degrade gracefully if the required JavaScript support is not present. The target element can be either a regular select box, or another activeselect box (which in turn can trigger another target box, which can trigger yet another, resulting in a hierarchical cascade of activeselect elements).') .'</p>';
}
}
/**
* Implementation of hook_elements().
*/
function activeselect_elements() {
$type['activeselect'] = array('#input' => TRUE);
return $type;
}
/**
* Converts the string of values passed to an activeselect callback function
* into an array.
*
* @param $string
* The string of values passed to an activeselect callback.
*
* @return
* An array of values, in the form $key => $value.
*/
function activeselect_explode_values($string) {
$array = explode('||', $string);
foreach ($array as $key => $value) {
$match = explode('|', $value);
$array[$match[0]] = html_entity_decode($match[1]);
unset($array[$key]);
}
return $array;
}
function activeselect_set_header_nocache() {
header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
/**
* Implementation of hook_theme().
*/
function activeselect_theme() {
return array(
'activeselect' => array('arguments' => array('element' => NULL)),
);
}
/**
* Format a dropdown menu or scrolling selection box.
*
* @param $element
* An associative array containing the properties of the element.
* Properties used: title, value, options, description, extra, multiple, required
* @return
* A themed HTML string representing the form element.
*
* It is possible to group options together; to do this, change the format of
* $options to an associative array in which the keys are group labels, and the
* values are associative arrays in the normal $options format.
*/
function theme_activeselect($element) {
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
$class = array();
$extra = '';
if ($element['#activeselect_path'] && $element['#activeselect_targets']) {
$module_path = drupal_get_path('module', 'activeselect');
drupal_add_css($module_path. '/activeselect.css');
drupal_add_js($module_path. '/activeselect.js');
$class[] = ' form-activeselect';
$extra = '<input class="activeselect-path" type="hidden" id="'. $element['#id'] .'-activeselect-path" value="'. check_url(url($element['#activeselect_path'], array('absolute' => TRUE))) .'" disabled="disabled" />'. "\n";
$targets = explode(',', $element['#activeselect_targets']);
foreach ($targets as $key => $target) {
$targets[$key] = 'edit-'. check_plain($target);
}
$extra .= '<input class="activeselect-targets" type="hidden" id="'. $element['#id'] .'-activeselect-targets" value="'. implode(',', $targets) .'" disabled="disabled" />'. "\n";
$extra .= '<input class="activeselect-extra" type="hidden" id="'. $element['#id'] .'-activeselect-extra" value="'. check_plain($element['#activeselect_extra']) .'" disabled="disabled" />'. "\n";
}
_form_set_class($element, $class);
return theme('form_element', $element, '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size. '>'. form_select_options($element) .'</select>'). $extra;
}
activeselect.js
// $Id: activeselect.js,v 1.18 2007/01/05 15:57:53 jaza Exp $
/**
* Attaches the activeselect behaviour to all required fields
*/
Drupal.activeselectAutoAttach = function () {
var asdb = [];
$('input.activeselect-path').each(function () {
var index = this.id.substr(0, this.id.length - 18);
var uri = this.value +'/'+ encodeURIComponent(index).substr(5);
var extra = $('#' + index + '-activeselect-extra').val();
var targets = $('#' + index + '-activeselect-targets').val();
var input = $('#' + index).get(0);
if (!asdb[uri]) {
asdb[uri] = new Drupal.ASDB(uri, targets);
}
new Drupal.jsAS(input, asdb[uri], targets, extra);
});
}
/**
* An ActiveSelect object
*/
Drupal.jsAS = function (input, db, targets, extra) {
var as = this;
this.input = input;
this.db = db;
$(this.input).change(function (event) { return as.onchange(this, event); });
this.extra = extra;
var targetsArray = targets.split(',');
this.targets = [];
for (var target = 0; target < targetsArray.length; target++) {
var newTarget = $('#' + targetsArray[target]).get(0);
newTarget.owner = this;
this.targets.push(newTarget);
}
// this only runs if the current element does not have a parent activeselect
// linked to it - otherwise, IE has problems.
if (!this.input.owner) {
this.populateTargets();
}
};
/**
* Handler for the "onchange" event
*/
Drupal.jsAS.prototype.onchange = function (input, e) {
if (!e) {
e = window.event;
}
this.populateTargets();
}
/**
* Return the currently selected options as a pipe-delimited string
*/
Drupal.jsAS.prototype.getSelectedOptions = function () {
var selectedOptions = [];
var maxWidth = 0;
$('#' + this.input.id + ' option').each(function () {
if (this.selected) {
var optionString = this.value.replace(/\|/g, '|') +'|'+ this.text.replace(/\|/g, '|');
selectedOptions.push(optionString);
}
if (this.text.length > maxWidth) {
maxWidth = this.text.length;
}
});
this.setSelectWidth(maxWidth);
return selectedOptions.join('||');
}
/**
* Sets the width and background position of the activeselect element.
*/
Drupal.jsAS.prototype.setSelectWidth = function (width) {
if (width != null) {
this.selectWidth = ((width * 10) * 1.5) + 20;
}
$(this.input).css({
width: this.selectWidth +'px',
backgroundPosition: (this.selectWidth - 35) +'px 2px'
});
}
/**
* Sets the width of the specified target element
*/
Drupal.jsAS.prototype.setTargetWidth = function (target, width) {
if (width != null) {
this.targets[target].targetWidth = (width * 10) * 1.2;
}
$(this.targets[target]).css({
width: this.targets[target].targetWidth +'px'
});
}
/**
* Starts a search
*/
Drupal.jsAS.prototype.populateTargets = function () {
var as = this;
this.db.owner = this;
this.db.search(this.getSelectedOptions(), this.targets, this.extra);
}
/**
* Fills the target select boxes with any matches received
*/
Drupal.jsAS.prototype.populate = function (matches) {
for (targetIndex in this.targets) {
var target = this.targets[targetIndex];
var matchesTarget = 0;
for (targetElement in matches) {
if ('edit-'+targetElement == target.id) {
matchesTarget = targetElement;
continue;
}
}
if (matchesTarget) {
this.targets[targetIndex].multiple = matches[matchesTarget]['multiple'];
if (matches[matchesTarget]['multiple']) {
if (target.name.indexOf('[]') == -1) {
this.targets[targetIndex].name += '[]';
}
}
else {
var bracketIndex = target.name.indexOf('[]');
if (bracketIndex != -1) {
this.targets[targetIndex].name = target.name.substr(0, target.name.length-2);
}
}
$(target).empty();
var targetMatches = matches[matchesTarget]['options'];
var maxWidth = 0;
for (currMatch in targetMatches) {
var value = currMatch;
var text = targetMatches[currMatch]['value'];
var selected = targetMatches[currMatch]['selected'];
if (text.length > maxWidth) {
maxWidth = text.length;
}
// 'new Option()' used instead of appendChild(), because IE6 refuses to
// display option text if the latter method is used (otherwise they seem
// to behave the same).
//$(this.targets[targetIndex]).append(new Option(text, value, false, selected));
if (navigator.appName == "Microsoft Internet Explorer") {
this.targets[targetIndex].add(new Option(text, value, false, selected));
}else{
$(this.targets[targetIndex]).append(new Option(text, value, false, selected));
}
if (selected && !this.targets[targetIndex].multiple) {
this.targets[targetIndex].selectedIndex = this.targets[targetIndex].options.length-1;
}
}
if (this.targets[targetIndex].selectedIndex == -1) {
this.targets[targetIndex].selectedIndex = 0;
}
if (this.hasClass(this.targets[targetIndex], 'form-activeselect')) {
// Since IE does not support the DOM 2 methods for manually firing an
// event, we must cater especially to its needs.
// Reference: http://www.howtocreate.co.uk/tutorials/javascript/domevents
if (document.createEvent) {
// DOM 2 compliant method (Firefox / Opera / Safari / etc)
var e = document.createEvent('HTMLEvents');
e.initEvent('change', true, false);
this.targets[targetIndex].dispatchEvent(e);
}
else if (document.createEventObject) {
// IE special weird method
var e = document.createEventObject();
e.bubbles = true;
e.cancelable = false;
this.targets[targetIndex].fireEvent('onchange', e);
}
}
else {
this.setTargetWidth(targetIndex, maxWidth);
}
}
}
this.setSelectWidth(null);
}
/**
* Returns true if an element has a specified class name
*/
Drupal.jsAS.prototype.hasClass = function (node, className) {
if (node.className == className) {
return true;
}
var reg = new RegExp('(^| )'+ className +'($| )')
if (reg.test(node.className)) {
return true;
}
return false;
}
/**
* An ActiveSelect DataBase object
*/
Drupal.ASDB = function (uri, targets) {
this.uri = uri;
this.targets = targets;
this.delay = 300;
this.cache = {};
}
/**
* Performs a cached and delayed search
*/
Drupal.ASDB.prototype.search = function(searchString, targets, extra) {
this.searchString = searchString;
if (this.cache[searchString]) {
return this.owner.populate(this.cache[searchString]);
}
if (this.timer) {
clearTimeout(this.timer);
}
var db = this;
this.timer = setTimeout(function() {
$(db.owner.input).css({
width: db.owner.selectWidth +'px',
backgroundPosition: (db.owner.selectWidth - 35) +'px -18px'
});
var targetIds = [];
for (var target = 0; target < targets.length; target++) {
if (targets[target].id) {
targetIds.push(targets[target].id.substr(5)); // Cambiado!!!
}
}
var targetsString = targetIds.join(',');
// Ajax GET request for activeselect
$.ajax({
type: "GET",
url: db.uri +'/'+ encodeURIComponent(targetsString) +'/'+ encodeURIComponent(searchString) +'/'+ encodeURIComponent(extra),
success: function (data) {
// Split into array of key->value pairs
if (data.length > 0) {
var targets = Drupal.parseJson(data);
if (typeof targets['status'] == 'undefined' || targets['status'] != 0) {
db.cache[searchString] = targets;
db.owner.populate(targets);
}
}
},
error: function (xmlhttp) {
db.owner.setSelectWidth(null);
alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ db.uri);
}
});
}, this.delay);
}
// Global Killswitch
if (Drupal.jsEnabled) {
$(document).ready(Drupal.activeselectAutoAttach);
}
Just download the current version and overwrite the files with this versions...
I hope it'll be a valid starting point to make a official port to D6.
Greetings,
Juan Arias
Spain
Comment | File | Size | Author |
---|---|---|---|
#1 | activeselect[unofficial_Hwangar_D6_port_August_21-2008].tar_.gz | 48 KB | Francewhoa |
Comments
Comment #1
FrancewhoaThanks Hwangar. I'm testing the above port to D6. I'll get back to you with my results.
If someone else want to test Active Select port to D6 I have attached to this post the module Active Select for Drupal 6. This is an unofficial version base on the above patch from Hwangar.
How to install the module:
Comment #2
dydecker CreditAttribution: dydecker commentedThis sounds interesting.
Is Active Select still dependent on the category module or can it be used with any form?
Comment #3
FrancewhoaHwangar: Here are my testing results with Active Select (August 21, 2008) downloaded from this page. Using a Drupal 6.4 fresh intall and Devel module to quickly generate dummy taxonomy.
The installation works. I see the module in module admin page.
Active Select widget for module Content Taxonomy can't be tested yet. The widget is not yet ported to Drupal 6. I have open a task.
Hope this testing help.
The following is a note to myself for future reference. Before using Active Select I must run cron to update the taxonomy index. Otherwise taxonomy won't work properly.
Comment #4
that0n3guy CreditAttribution: that0n3guy commentedHow do you test this without the Active Select widget for module Content Taxonomy?
I have installed it and activated it on drupal 6.4, and I didn't get any errors... so that seems good.
Comment #5
toitimhcm CreditAttribution: toitimhcm commentedI just patched widget an attack at my web Link check. download here http://drupal.org/node/302397#comment-1082529
-------------
Comment #6
Micha1111 CreditAttribution: Micha1111 commentedI tested the unofficial version above in combination with category_6.x-2.0-alpha4 and it works fine.
The containers and categories from category-module are saved as nodes, so I wonder, if there is an easy way to use "active select" for custom cck-nodereference-fields, because its the same stucture of data (simple nodes with relations) in my following example.
I have 4 content-types:
"Leagues": Number,Name
"Teams": Number,Name,inLeague (nodereference-field to content-type "Leagues")
"Players": Number,Name,inTeam (nodereference-field to content-type "Teams")
and the main-type "Pairs":
ofleague (nodereference-field -select- to content-type "Leagues")
team_home (nodereference-field -select- to content-type "Teams")
team_guest (nodereference-field -select- to content-type "Teams")
team_result (text-field)
player_home (multiselect nodereference-field to content-type "Players")
player_guest (multiselect nodereference-field to content-type "Players")
player_result (multiselect text-field)
At the moment, its difficult and not userfriendly to select 1 of 10 Leagues, 1 of 100 Teams and 1 of 1000 Players from select lists.
It would be easier, if the user, who adds a new pair, could at first choose a league
in the next select lists for team_home and team_guest only teams from the choosen league should be available
in the next select list for player_home only players from team_home should be available
in the next select list for player_guest only players from team_guest should be available
I can't use the category-module for this , because its not possible to use a category select-list-field twice in the same form like nodereference-fields.
I hope, there is somebody, who can support this feature.
Comment #7
that0n3guy CreditAttribution: that0n3guy commentedI posted my attempt to update the activemulti widget to D6 here: http://drupal.org/node/180687#comment-1103044
I based it all on what toitimhcm did (see #5 above) and ran it through coder module. As such, it doesnt seem to be referencing activeselect (just like toitimhcm's port) so if anyone can look at it really quick, that would be amazing!!
Comment #8
Hwangar CreditAttribution: Hwangar commentedHello guys,
after check the state of Hierarchical Select, and knowing that Wim is quite busy right now, the case is that I need to handle a huge hierarchy and cannot let users deal with the giant select (default implementation), so I decided recheck this module again and add a couple of features...
you can view it fully working here:
http://www.automotoocasion.com (the right searching block is based on the vocabulary)
I'm thinking about substituting the term-selector in node edits with this...
if anyone wants to add features, say now or shut up forever!!! :P
ok, I'll keep you informed
Juan Arias
Comment #9
that0n3guy CreditAttribution: that0n3guy commentedAwesome, thanks for showing your site to verify it works.
The only other features I'd go for are to have some content_taxonomy widgets working... especially this one: http://drupal.org/node/180687
I think its very close to working, it just needs someone who knows activeselect to look at it.
Comment #10
no2e CreditAttribution: no2e commentedsubscribing
Comment #11
scott859 CreditAttribution: scott859 commentedsubscribing
Comment #12
adf1969 CreditAttribution: adf1969 commentedI am trying to use the D6 port and am having the following issue (my code is at the end of this post):
My ActiveSelect works as the functionality is intended (as it relates to ActiveSelect. Fields load values with Ajax, fields can be selected, fields are "dependent" as expected).
Where the problem occurs is if I hit the "preview" or "save" buttons.
If I do that, I get the following error
The following is content.module:1234 :
I stepped through the entire form_builder() execution to see what was causing the error, and it appears that the following is the issue:
* When I turn "off" the ActiveSelect (and leave both CCK fields as plain old SELECT elements, the POST value for each of them is as follows:
* When I turn "on" the ActiveSelect, the POST values for each of the ActiveSelect elements is as follows:
I do not know why this is. I'm guessing it must have something to do with how ActiveSelect builds the actual "select" element on the client. I also noticed that the select "name" attribute is: "field_ref_pmproperty[nid][nid]" with ActiveSelect turned off, but is just: "field_ref_pmproperty" with ActiveSelect turned on.
I'm hoping that someone who understands FAPI and "widgets" can explain to me what the solution is.
I spent considerable time figuring out ActiveSelect and could really put it to use, then spent a bunch of time on this issue, and now I'm wondering if I should just skip using ActiveSelect entirely because I think solving this issue is a bit beyond me (I just don't understand how the POST value gets set in Drupal so am not even sure where to begin...this issue went from an ActiveSelect issue, into a Drupal core issue...which is out of my league...)
Here is my ActiveSelect implementation code:
Comment #13
jazzitup CreditAttribution: jazzitup commentedWhere can I download the most recent dev-version of this module for D6?
Comment #14
FrancewhoaHi madjoe,
Usually most recent dev-version of this module are available on this page under section 'activeselect HEAD' or section 'activeselect 6.x-1.x-dev':
http://drupal.org/node/49976/release
But there's no Drupal 6 section/branch setup yet. Only the module maintainer can open a new branch. Current module maintainer is Jaza http://drupal.org/user/15277
I have created a new task today asking to create a new branch: http://drupal.org/node/433022
In the meantime you could ask one of the above testers and or developers to post on this page a tarbal file or a zip file of their latest dev-version: http://drupal.org/node/298230
Comment #15
melban CreditAttribution: melban commentedsubscribing
Comment #16
psboegh CreditAttribution: psboegh commentedStill no tar-ball available? I understand the module is working - at least as a -dev version?
If Drupal maintainence cannot keep up, can you please redirect us to an alternative server to download?
Comment #17
iaminawe CreditAttribution: iaminawe commentedsubscribe
Comment #18
pankajshr_jpr CreditAttribution: pankajshr_jpr commentedno tar till now ?? someone cud upload it on different server for use in between it wud hv the development patch?
Comment #19
FrancewhoaHow to deal with abandoned projects: http://drupal.org/node/251466
Following above procedure I have created a new post: http://drupal.org/node/471318
Comment #20
Summit CreditAttribution: Summit commentedSubscribing, greetings, Martijn
Comment #21
Summit CreditAttribution: Summit commentedHi Toitim, Your link to the widget is not working anymore, please adjust.
Thanks in advance!
Comment #22
CarbonPig CreditAttribution: CarbonPig commentedsubscribe
Comment #23
tiuman CreditAttribution: tiuman commentedPlease dont. Stop dev!!!
Comment #24
drupov CreditAttribution: drupov commentedsubscribe
Comment #25
b2bweb CreditAttribution: b2bweb commentedsubscribing...
Comment #26
velam CreditAttribution: velam commentedGents, interesting, will this module work with Drupal 7 ? Is it difficult to port to D7 ?
Can we use it instead of hierarchical select?
I am seeking for answer on usual problem: select country -> select region -> select city
Comment #27
NewZeal CreditAttribution: NewZeal commentedNo port currently in the pipeline.