Select menu contents dependent upon another select menu sele

A place for users and developers of the Xataface to discuss and receive support.

Postby freakingid » Thu Sep 27, 2007 7:33 am

I cannot think of a better way to word that title! Sorry...

I have one table that we can call "Categories."
I have another table that we can call "Subcategories."
Each "subcategory" item has one parent "category" item.
This means "Category 1" might own "Subcat A," "Subcat B," and "Subcat C", and "Category 2" might own "Subcat D," "Subcat E," and "Subcat F."

I would like for people entering data to:
1. Select a "Category" from a select list.
- no problem, dataface makes this easy.

2. Select a "Subcategory" from a select list, but have the contents of that select list change based on the "Category" they choose from the first select list.

Is there a way to do this in Dataface?
Ajaxy stuff?
Or a multi-page insert method? (i.e. the user would select the "Category" on the first page, then the second page would have knowledge of the selected category from a POST variable, perhaps.)

Thanks, Dataface is wonderful.
Paul
freakingid
 
Posts: 1
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Sep 27, 2007 9:37 am

There isn't an automatic way to do this, however, it can be done. I generally use javascript for this, and there are multiple methods.

One key that makes this possible is that you can add a third column to the SQL query of a valuelist that is treated as a category.
e.g.

valuelists.ini:
Code: Select all
;; Products valuelist
[cities]
    __sql__ = "select city_id, city_name, province_id from cities"

;; Product categories valuelist
[provinces]
    __sql__ = "select province_id,province_name from provinces"


fields.ini:
Code: Select all
[province]
    vocabulary=provinces

[city]
    vocabulary=cities


delegate class:
Code: Select all
...
function block__after_new_record_form(){
    echo <<   
END;
}

// Also place this javascript after an edit record form...
function block__after_edit_record_form(){
    return $this->block__after_new_record_form();
}




Note that the above code uses the PEAR Services_JSON class to convert a PHP array to a Javascript array. I'm not sure if this is included in the Dataface distribution or not. (Check to see if dataface/lib/Services/JSON.php exists). If not you can download it from pear.php.net

References:
http://www.quirksmode.org/js/options.html - Working with select lists in javascript.

You make also want to check out this thread for discusson on doing this using AJAX.
http://framework.weblite.ca/forum/dataface-users/129880730

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Fri Feb 15, 2013 2:20 am

Hi,
sorry for my English

i have read much of this posts but every time i try something, i always fail.

i will do the same like the guy above:
my valuelist.ini:

[bautl]
__sql__ = "SELECT Bauteile.ID, Bezeichnung FROM Bauteile"

[auspr1]
__sql__ = "SELECT Auspraegung1.ID, CONCAT(Bezeichnung, ' (', Identifikation, ')') FROM Auspraegung1"

my fields.ini:

[Bauteile_ID]
widget:type = select
vocabulary = bautl
group = wichtig
oder = 3

[Auspraegung1_ID]
widget:type = select
vocabulary = auspr1
group=Auswahl
oder = 6

delegate class konfiguration.php:

at the moment there are nothing special


________
Bauteile_ID and Auspraegung1_ID are Fk in the konfiguration table.
also Bauteile_ID is a Fk in the Auspragung1 table.

someone should select Bauteile_ID and then, in Auspragung1_ID only should stay the values with the same ID which are selected above.

thank you for your help
Regards

Max
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am

Re: Select menu contents dependent upon another select menu

Postby auphi » Fri Feb 15, 2013 2:20 pm

baureggerM:

This is a really old post. Check out the depselect module: http://xataface.com/dox/modules/depselect/latest/

That should let you do what you are wanting.
auphi
 
Posts: 20
Joined: Sun Oct 21, 2012 7:39 pm

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Sat Feb 16, 2013 4:23 am

Hi,

thank you very much at the moment i cant try this.
is this automaticly installed in the newest version of Xataface ?
at the link i can't download the module

thank you

Max
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Mon Feb 18, 2013 12:17 am

Hey,

i copy all files out of the SVN and write the properties in my fields.ini

but in the moment i write "widget:type = depselect"

the whole page is white

Max
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am

Re: Select menu contents dependent upon another select menu

Postby shannah » Tue Feb 19, 2013 1:38 pm

Check your php error log to see what the problem is. Likely the depselect module is not installed properly. Make sure you have added the appropriate line to the [_modules] section of your conf.ini and that you have installed the depselect folder inside the modules directory.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Tue Feb 19, 2013 11:38 pm

Hi,
this was the error:

[20.02.2013 07:34:30] JavaScript - http://10.29.3.114/#######/index.php?-table=Konfiguration&-action=history&-cursor=2&-skip=0&-limit=30&-mode=list&-recordid=Konfiguration%3FID%3D4
Event thread: mouseup
Uncaught exception: ReferenceError: Undefined variable: activeButton
Error thrown at unknown location in <anonymous function>(event) in http://10.29.3.114/######/index.php?-table=Konfiguration&-action=history&-cursor=2&-skip=0&-limit=30&-mode=list&-recordid=Konfiguration%3FID%3D4:
/* no source available */ <------------- ????????????


the conf.ini :

[_modules]
modules_depselect=modules/depselect/depselect.php


inside of "xataface/modules/depselect" are all the files i found in the VDD

thanks for all Max



______________________________________________________________________________________________________

we update no to the 2.0.0alpha and now all is OK only on the text fields are no drop-down menus
also at the ordinary Select menus the "Other..." function don't work
this is my last problem this tool is very good :-D, and i need only once help ! :-D
thanks

great job good tool
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am

Re: Select menu contents dependent upon another select menu

Postby shannah » Wed Feb 20, 2013 10:39 am

Was that a PHP error log or a Javascript error log?

Try moving the depselect module into your application's modules directory. It should work in either location, but it is worth a shot.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Wed Feb 20, 2013 11:42 pm

Hey,
i have done the depselect order in both modules directories already. but now at xataface 2.0.0 alpha i have much new error's of my Opera error-console
right of the date time stand the kind of error js or CSS in this exception (i believe only error 5 is important)

1. -
[21.02.2013 07:35:21] CSS - http://10.29.3.114/xataface-2.0alpha1/plone.css
Linked-in stylesheet
Invalid value for property: list-style
Line 1706:
list-style: visible;

2. -
[21.02.2013 07:35:21] CSS - http://10.29.3.114/xataface-2.0alpha1/plone.css
Linked-in stylesheet
Declaration syntax error
Line 2588:
dth:100%;background:#000;-moz-opacity:0.10;opacity:.10;filter:alpha(opacity=10);

3. -
[21.02.2013 07:35:21] CSS - http://10.29.3.114/#######/index.php?-action=new&-table=Konfiguration
HTML style attribute
Invalid value for property: zoom
Line 1:
rder:0;display:block;overflow:hidden;width:1px;padding:1px;display:inline;zoom:1

4. -
[21.02.2013 07:35:21] CSS - http://10.29.3.114/#######/index.php?-action=new&-table=Konfiguration
DOM style property
Invalid value for property: zoom
Line 1:
1

5. -
[21.02.2013 07:35:21] JavaScript - http://10.29.3.114/######/index.php?-action=new&-table=Konfiguration
Event thread: DOMContentLoaded
Uncaught exception: TypeError: '$(this).RecordDialog' is not a function
Error thrown at line 752, column 9 in <anonymous function>() in http://10.29.3.114/######/index.php?-action=new&-table=Konfiguration:
$(this).RecordDialog({
called via Function.prototype.call() from unknown location in <anonymous function: each>(a, c, d) in http://10.29.3.114/xataface-2.0alpha1/j ... .packed.js:
/* no source available */
called from line 18, column 22268 in <anonymous function: each>(a, b) in http://10.29.3.114/xataface-2.0alpha1/j ... .packed.js:
return p.each(this,a,b)
called from line 746, column 8 in <anonymous function>($) in http://10.29.3.114/#######/index.php?-action=new&-table=Konfiguration:
$("#Auspraegung1_ID-other").each(function(){
called via Function.prototype.apply() from line 18, column 33780 in <anonymous function: p.Callbacks>(b) in http://10.29.3.114/xataface-2.0alpha1/j ... .packed.js:
if(i[h].apply(b[0],b[1])===!1&&a.stopOnFalse)
called from line 18, column 35298 in <anonymous function: fireWith>(a, b) in http://10.29.3.114/xataface-2.0alpha1/j ... .packed.js:
return b=b||[],b=[a,b.slice?b.slice():b],i&&(!d||j)&&(e?j.push(b):k(b)),this
called from line 18, column 24730 in <anonymous function: ready>(a) in http://10.29.3.114/xataface-2.0alpha1/j ... .packed.js:
d.resolveWith(e,[p]),p.fn.trigger&&p(e).trigger("ready").off("ready")
called from line 18, column 19535 in <anonymous function>() in http://10.29.3.114/xataface-2.0alpha1/j ... .packed.js:
e.addEventListener?(e.removeEventListener("DOMContentLoaded",D,!1),p.ready()):e.readyState==="complete"&&(e.detachEvent("onreadystatechange",D),p.ready())


- Max


________________________________________________________
is my fields. ini wrong ?
this is in the Konfiguration table there are 2(and much more) Fk's Bauteile_ID and Typ_ID.
inside of Typ_ID ( Bauteile_ID is a FK)

[Bauteile_ID]
widget:type = depselect
widget:table = Bauteile
vocabulary = bautl
group = wichtig
order = 3

[Typ_ID]
widget:type = depselect
widget:table = Typ
widget:filters:Bauteile_ID = "$Bauteile_ID"
vocabulary = Typ
group=Auswahl
order = 5

-Max

____________________________________________
again : i tested the errors without depselect in the fields-ini

all errors are the same ......


in the widget.php the
Code: Select all
$jt->import('xataface/widgets/depselect.js');

the script was not found. We change the path to modules/depselect/js/.....
but the java script was never put out as we checked in the source code of the HTML site.

An echo of the js (after the import function) to the html site seemed to add the drop-down menu but only with the modules/depselct/js..... path

thanks for all Max
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Thu Feb 21, 2013 2:50 am

Hi,

we solved that problem with the
http://xataface.com/wiki/index.php?-tab ... e_id=%3D90

now i have to try this on more than one function :-D

ok i thing is left : by the other function is a Bug

at :

Code: Select all
                     jQuery(document).ready(function($){
                        $("#Bauteile_ID-other").each(function(){
                           var tablename = "Bauteile";
                           var valfld = "Bezeichnung";
                           var keyfld = "ID";
                           var fieldname = "Bauteile_ID";
                           var btn = this;
                           $(this).RecordDialog({
                              table: tablename,
                              callback: function(data){
                                 var key = data[keyfld];
                                 var val = data[valfld];
                                 $("#"+fieldname).append('<option value="'+key+'">'+val+'</option>');
                                 $("#"+fieldname).val(key);
                                 
                              }
                           });
                        });
                     })


is a error :
"Unhandled Error: '$(this).RecordDialog' is not a function"

thanks
-Max
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am

Re: Select menu contents dependent upon another select menu

Postby shannah » Thu Feb 21, 2013 10:05 am

Where is that source code snippet taken from? Is this your code or from Xataface file?
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Select menu contents dependent upon another select menu

Postby baureggerM » Fri Feb 22, 2013 2:09 am

hey,

this is a javascript output from Dragonfly a Opera Javaskript "debugger" to know what is going wrong.
after press the "Other.." button the ordinary pop up menu -to fill in the new Value- is now at the bottom of the side
after fill in somthing in the Textfilds press save and the the site is pictured doubeld sems like 3D :-P
always have to reload the page then is all ok and the value is saved
i have nothing change this filde should be written from Xataface developers :-D perhapes you

thanks
- Max
baureggerM
 
Posts: 9
Joined: Fri Feb 15, 2013 2:10 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved