Categories > TinyButStrong general >

Another one: listboxes - more than one value for a key

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: magictrickpony
Date: 2004-06-16
Time: 16:54

Another one: listboxes - more than one value for a key

Dear all,

Unfortunately i have run into another problem.

I want to generate a listbox with several values (aka options) for one key (name).

$key-----+--$val[0]
              |
              +--$val[1]

$ItemList[$key] = array ('true' => '1', 'false' => '0');

according the documentation we're dealing with array with indices

$ItemLists[] = array ('value'=>'TRUE', 'id'=>1);
$ItemLists[] = array ('value'=>'FALSE', 'id'=>0);

Unfortunately If I fit a third key with value in, like 'key' it doesn't do a nested, hierachical pull down menu.

$ItemLists[] = array ('key'=>'boolean_field', 'value'=>'TRUE', 'id'=>1);
$ItemLists[] = array ('key'=>'boolean_field', 'value'=>'FALSE', 'id'=>0);


boolean_field-----+--TRUE
                          |
                          +--FALSE
                           |
                           +--(etc..)

Please advise. Thanks
By: Skrol29
Date: 2004-06-17
Time: 00:52

Re: Another one: listboxes - more than one value for a key

Hi,

I don't understand what your trying to do.
Could you precise what kind of herarchical menu you want to do ?
By: magictrickpony
Date: 2004-06-17
Time: 08:55

Re: Another one: listboxes - more than one value for a key

Alors, let's give it a try...

My database table has several fields with different types:

field.a is of type integer
field.b is of type text
field.c is of type boolean (binary)

For fields that are either integer or text i want to display a html form text input field. --> that is not the problem.

For fields that are boolean (or binary) for that fact, there are two possible values that the field can have, if we're talking boolean it can either have the value "true" or "false" (with binary, obviously this is "1" or "0").

Because of that i don't want to have a html form text input field, but a dropdown menu, which lists all possible choices according to the type of the field.

So what i wanted to do is..

$ItemList[$key] = array ('true' => '1', 'false' => '0');

Where $key would be each database field which is for example of type "boolean".

i.e.

$ItemList["field.c"] = array ('true' => '1', 'false' => '0');

Because it is likely that there are several database fields of type boolean in a table,  i need a reference to which field is being processes. This is what i am currently unable to figure out how to do.

$ItemList["field.c"] = array ('true' => '1', 'false' => '0');
$ItemList["field.d"] = array ('true' => '1', 'false' => '0');
$ItemList["field.e"] = array ('On' => '1', 'Off' => '0');

(unfortunately I cannot get this to work)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
  <title>1</title>
</head>
<body>
<table border="1" align="center" cellpadding="2" calign="center" cellspacing="0">
<tr><td>field.c</td><td>
<select name="field.c">
<option value="1">TRUE</option>
<option value="0">FALSE</option>
</select></td></tr>
<tr><td>field.d</td><td>
<select name="field.d">
<option value="1">TRUE</option>
<option value="0">FALSE</option>
</select></td></tr>
<tr><td>field.e</td><td>
<select name="field.e">
<option value="1">ON</option>
<option value="0">OFF</option>
</select></td></tr>
</table>
<br>
<br>
</body>
</html>

p.s.: another question would be if i stick all that info in a seperate MergeBlock(), is there a way if there are no boolean/binary fields to skip on the HTML part, without displaying "Can't merge because there is no key"?
By: Skrol29
Date: 2004-06-18
Time: 02:54

Re: Another one: listboxes - more than one value for a key

Hi,

I think I well understand now.

What you need to do, is a "main-block + sub-block" structure with a data source which is an Array. Sub-blocks are possible with TBS but only with data source using string queries (SQL).

I think I gonna add a feature for sub-block with array data source.
But for now here are many solutions:

* Using sub-blocks (complicated but smart):
Main-block should be the Field list, sub-block should be the item list, and parameter 'p1' should be on the type id. (see manual for more information about p1)
But because of what I told before, you will have to code custom data source functions for the sub-blocks. For a given p1 value, the function will have to return the items for type p1.

* Using 1 block (easy and aswer your last question):
Instead of saving items of a given type into an Array, you can save the Html definition instead.
Example :
$TypeDef['boolean'] = '<select name="xxx"><option value="1">TRUE</option><option value="0">FALSE</option></select>';
$TypeDef['onoff'] = '<select name="xxx"><option value="1">ON</option><option value="0">OFF</option></select>';
$TypeDef['varchar'] = '<input type="text" name="xxx">';

And your field list:
$FieldLst[] = array('name'=>'field.a','type'=>'boolean');
$FieldLst[] = array('name'=>'field.b','type'=>'onoff');
$FieldLst[] = array('name'=>'field.c','type'=>'varchar');
You just have to find a little tric to replace xxx by the field name.
By: magictrickpony
Date: 2004-06-21
Time: 09:21

Re: Another one: listboxes - more than one value for a key

Hi!

Thanks for your help. With your feedback i was able to find a way around my problem.

Merci beaucoup!