This topic is locked

drop down dependant on multiple options (4.2)

10/7/2008 8:18:49 PM
PHPRunner General questions
U
unimatrix author

I'm using version 4.2 and building a backend to control an ecommerce site.
When an admin adds a product, he can choose what option categories belong to that item. It is a multi-line select as a T-shirt could have the option categories Size, color, etc.
Then in the box below is an options box that is also a multi-line drop down that would hold things like small, med, large and RED, BLUE, YELLOW respectively.
Well It works fine when the user selects only one category. But if they select two or more categories, only the first selected category is displayed. It is so close to working that it's almost like I need to make a small hack to make it work.
Is there a way to display the selected items for all 3 categories or an idea of what function I will need to hack to get it to do so?

J
Jane 10/10/2008

Hi,
It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

U
unimatrix author 11/16/2008

This got pushed to my back burner of things to do, but I'm back at it. I tried uploading to the demo account, but got an error when it was trying to create the tables.
So I did the next best thing: create a screen video showing what I am talking about:
http://www.deliverstous.com/multiple_select_1.swf
So long as one is selecting 1 option category, things work fine. The problem comes when we need items from multiple categories to appear in the options multiple select box.
I'll use the example of Sandwiches because it is the least confusing. Sandwiches need to have options available from 2 Option Categories: Chips and Sandwich Options. When each category is selected, the values of all the selected categories should appear in the Options multiple select box below it.
Likely this is located somewhere in the javascript for the pages. I just need help finding where in it is the javascript in order to make the necessary changes.

J
Jane 11/17/2008

Hi,
please zip and send a ful set of generated files, your project file along with your database creation script or database dump to support@xlinesoft.com for investigation.

U
unimatrix author 11/20/2008

I've rebuilt and uploaded the project to the demo account under phprunner 5.0, still cannot select multiple categories in a multiline drop-down menu and have all the selected options appear, but I was able to upload to the demo account with no errors.

J
Jane 11/21/2008

Please send to support@xlinesoft.com a URL to your pages on the Demo Account along with instructions on reproducing this error.

W
wildwally 11/22/2008

How would one go about doing something like this? Would it be a query? If so where do you put that, custome code? What would this look like to look for two conditions from one table? I created a custom view using the query builder thinking this would be the way to do it, but the visual editor doesn't look see this as a table to select from.

U
unimatrix author 12/15/2008

Hi all, we've been working on this and have gotten about 90% of the way there. We should have a finished and completely working version of this finished by the end of the week. But this is an alpha build of our code and it mostly works. We found the code in ajaxsuggest.js and have taken to modify it and we're just going to attach it with a BSD license. Here is what we've got so far:

/*

* Copyright (c) 2008, Common Ground Technologies, a wholly owned subidary of

* Common Grounds Coffee House, Inc.

* All rights reserved.

*

* Redistribution and use in source and binary forms, with or without

* modification, are permitted provided that the following conditions are met:

* * Redistributions of source code must retain the above copyright

* notice, this list of conditions and the following disclaimer.

* * Redistributions in binary form must reproduce the above copyright

* notice, this list of conditions and the following disclaimer in the

* documentation and/or other materials provided with the distribution.

* * Neither the name of Comomon Grounds Coffee House, Inc. nor the

* names of its contributors may be used to endorse or promote products

* derived from this software without specific prior written permission.

*

* THIS SOFTWARE IS PROVIDED BY COMMON GROUNDS COFFEE HOUSE, INC. ''AS IS'' AND ANY

* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

* DISCLAIMED. IN NO EVENT SHALL COMMON GROUNDS COFFEE HOUSE, INC. BE LIABLE FOR ANY

* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND

* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

function preloadSelectContent(txt, selectControl, selectValue, record_id)

{

if(record_id!="")

record_id="_"+record_id

if($('#'+selectControl+record_id)[0].tagName=='SELECT')

{

var j=0;

var lookup = $('#'+selectControl+record_id).get(0);

lookup.options[0]=new Option(TEXT_PLEASE_SELECT,'');

var str = txt.split('\n');

var index = 0;

for(i=0; i < str.length - 1; i=i+2, j++) {

lookup.options[j+1]=new Option(unescape(str[i+1]),unescape(str[i]));

if ( unescape(str[i]) == selectValue ) {index = j+1;}

}

lookup.selectedIndex = index;

if ( j == 1 && selectValue=="") { lookup.selectedIndex = 1; }

}

else if(txt.length)

{

var str = txt.split('\n');

if(str.length==3)

{

$('#'+selectControl+record_id).val(unescape(str[0]));

$('#display_'+selectControl+record_id).val(unescape(str[1]));

}

}

}
function preloadMultiSelectContent(txt, selectControl, selectValue, record_id)

{

if(record_id!="")

record_id="_"+record_id

var j=-1;

var lookup = $('#'+selectControl+record_id).get(0);

var str = txt.split('\n');

var sel = selectValue.split('\n');

var index = 0;

for(i=0; i < str.length - 1; i=i+2, j++)

{

lookup.options[j+1]=new Option(unescape(str[i+1]),unescape(str[i]));

for(k=0;k<sel.length-1;k++)

if ( unescape(str[i]) == unescape(sel[k]) )

{

lookup.options[j+1].selected=true;

break;

}

}

}
/**

* caching support added by nathan nobbe, (c) moxune 2008; moxune.com

*/

window.optionCategoryOptionsCache = {

cachedIds : [],

cachedNames : [],

cachedCategoryOptionIds : [], // indexed by cachedIds

cachedCategoryOptionNames : [], // indexed by cachedIds

_lastId : -1,

add : function(id, name) {

if(this.findById(id) !== false) return false;

this.cachedIds.push(id);

this.cachedNames.push(name);

},

addOptionById : function(id, optionId, optionName) {

if(!this._find(id, this.cachedIds)) return false;

if(this.findOptionById(id, optionId) !== false)

return false;

if(!(this.cachedCategoryOptionIds[id] instanceof Array))

this.cachedCategoryOptionIds[id] = [];

if(!(this.cachedCategoryOptionNames[id] instanceof Array))

this.cachedCategoryOptionNames[id] = [];

this.cachedCategoryOptionIds[id].push(optionId);

this.cachedCategoryOptionNames[id].push(optionName);

},

removeById : function(id) {

if(this.findById(id) !== false) return;

this._removeByLastId();

},

removeByName : function(name) {

if(this.findByName(name) !== false) return;

this._removeByLastId();

},

removeOptionsById : function(id) {

if(this.findById(id) !== false) return;

this.cachedCategoryOptionIds[id] = [];

this.cachedCategoryOptionNames[id] = [];

},

findByName : function(name) {

return this._find(name, this.cachcedNames);

},

findById : function(id) {

var buffer = this._find(id, this.cachedIds);

if( (buffer !== false) &&

(this.cachedCategoryOptionIds[id] instanceof Array) )

return buffer;

return false;

},

findOptionsById : function(id) {

if(!this.findById(id)) return false;

if(!(this.cachedCategoryOptionIds[id] instanceof Array))

return false;

var results = [];

for(var m in this.cachedCategoryOptionIds[id]) {

if( ($.isFunction(this.cachedCategoryOptionIds[id][m])) ||

(this.cachedCategoryOptionIds[id][m] == undefined) )

continue;

results.push(this._returnResultObject(

this.cachedCategoryOptionIds[id][m],

this.cachedCategoryOptionNames[id][m]));

}

return results;

},

findOptionById : function(id, optionId) {

if(!this.findById(id)) return false;

if(!(this.cachedCategoryOptionIds[id] instanceof Array))

return false;

for(var i in this.cachedCategoryOptionIds[id])

if(optionId == this.cachedCategoryOptionIds[id][i])

return this.cachedCategoryOptionIds[id][i];

return false;

},

_find : function(value, arrayToSearch) {

for(var i in arrayToSearch)

if(value == arrayToSearch[i]) {

this.lastId = i;

return this._returnResultObject(

this.cachedIds[i], this.cachedNames[i]);

}

return false;

},

_returnResultObject : function(id, name) {

return {id : id, name : name, type : 'OPTION'};

},

_removeByLastId : function() {

var _cachedIds = [];

var _cachedNames = [];

for(var i=0; i<this.cachedIds.length; i++) {

if(i == this._lastId) continue;

_cachedIds.push(this.cachedIds[i]);

_cachedNames.push(this.cachedIds[i]);

}

this.cachedIds = _cachedIds;

this.cachedNames = _cachedNames;

}

}
function loadSelectContent(table,main_field, dependent_field, record_id)

{

var field = myEncode( dependent_field );

var value = myEncode( $('#value_'+main_field+record_id).val() );

var type = $('#value_'+dependent_field+record_id)[0].tagName;

var selectedOptionCategories = $("#value_"+main_field+" option:selected");
var updateUi = function(txt) {

var selectedOptionCategories = $("#value_"+main_field+" option:selected");

selectedOptionCategories.scrollable = true;

if($('#value_'+dependent_field+record_id)[0].tagName=='SELECT') {

var targetSelect =$('#value_'+dependent_field+record_id)[0];

var j=0;

var str = txt.split('\n');

var optionsAndOptgroups = '';

if(!targetSelect.multiple)

targetSelect.innerHTML='<option value="">'+TEXT_PLEASE_SELECT+'</option>';

else {

targetSelect.innerHTML='';

j=-1;

}

selectedOptionCategories.each(function(i, e) {

var options = '';

var _e = $(e);

var cachedOptions = window.optionCategoryOptionsCache.findOptionsById(

_e.val());

if(cachedOptions === false) {

for(i=0; i < str.length-1; i=i+=2) {

window.optionCategoryOptionsCache.addOptionById(

selectedOptionCategories.val(), unescape(str[i]), unescape(str[i+1]));

options += '<option value="'+unescape(str[i])+'>'+unescape(str[i+1])+'</option>';

}

} else {

for(i in cachedOptions)

if(cachedOptions[i].type && cachedOptions[i].type == 'OPTION')

options += '<option value="'+cachedOptions[i].id+'>'+cachedOptions[i].name+'</option>';

}

optionsAndOptgroups += '<optgroup label="'+_e.html()+'">'+options+'</optgroup>';

});

$(targetSelect).html(optionsAndOptgroups);

} else {

$('#value_'+dependent_field+record_id).val("");

$('#display_value_'+dependent_field+record_id).val("");

if(txt.length) {

var str = txt.split('\n');

if(str.length==3) {

$('#value_'+dependent_field+record_id).val(unescape(str[0]));

$('#display_value_'+dependent_field+record_id).val(unescape(str[1]));

}

}

}

}
if(window.optionCategoryOptionsCache.add(

selectedOptionCategories.val(),

selectedOptionCategories.html()) !== false) {

if(record_id!="")

record_id="_"+record_id

$.get(table+"_autocomplete.php",

{

field: field,

value: value,

type: type

}, updateUi);

} else {

var txt = '';

var options = this.optionCategoryOptionsCache.findOptionsById(selectedOptionCategories.val());

window.myoptions = options;

for(var n in options)

if(options[n] !== undefined)

txt += options[n].id + '\n' + options[n].name + '\n';

updateUi(txt);

}

}


We have the display part done, now is getting it to format the output correctly to add into the database id records like 23,35,123,1234,11,34,22 etc..
When we have the finished code done, I'll delete this and post the working version, again under a BSD license so whomever wants to use it can. Open for suggestions/comments.