multi choice

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

multi choice

Post by baudwalker » 2018-04-26 06:04

Hi All

I have a table with one field that contains jobs

I wish to use that list of jobs in the same manner as the "option list" so the user is able to select multiple jobs.

The user needs to be able to add more jobs to select from as required so the "option list" is not an option.

any suggestions?

Barry

bescott53

Re: multi choice

Post by bescott53 » 2018-04-27 14:36

Can you not use the `options list` and from there select the multiple-choice list box.

Bertv
Veteran Member
Posts: 65
Joined: 2013-12-11 15:59

Re: multi choice

Post by Bertv » 2018-04-27 15:36

You have to use a csv-file for the options.
optionlist.png
optionlist.png (75.14 KiB) Viewed 6964 times
In the the table with the options you have to create the options csv file int the after insert and after update hook.
See below an example:

function adm_mail_groepen_after_insert($data, $memberInfo, &$args){
// stel de mailgroepenlijst t.b.v.mailingen opnieuw samen
$csvfile = "adm_mailingen.mln_mailgroep.csv";
// - stel de mailgroepenlijst opnieuw samen
$sql_string = "SELECT mgr_naam
FROM adm_mail_groepen";
$resultaat = sql($sql_string, $eo);
$num_rows = db_num_rows($resultaat);
$list = "";
if ($num_rows > 0) {
while ($rij = db_fetch_array($resultaat)) {
if(!$list) {
$list = $rij["mgr_naam"];
} else {
$list = $list . ";;" . $rij["mgr_naam"];
}
}
}
// - save de csv-file
$file = fopen("hooks/$csvfile", "w");
fwrite($file, $list);
fclose($file);

return TRUE;
}
Bert
I am using Appgini 5.75

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: multi choice

Post by baudwalker » 2018-04-28 00:49

Thank you, both bescott53 and Bert,

The task is to have a dropdown list with multiple choice options, similar to the 'options list'. but the user needs to be able to add or remove items as required.

Over time, more and more items will be added to the list. The user will not be able to populate the 'options list' as they will not have asses to AppGini or the server.

What is required is a field in a table that will populate a dropdown list. Then the user will be able to add multiple items to the list as required.

Bert your CSV method is worth a good look, but the user will have to be able to update the CSV file.

As with most end users they are no Einstein, so KISS is of the essence.

Once again thank you

Barry

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: multi choice

Post by pbottcher » 2018-04-29 07:53

Hi Baudwalker,

I think you can acheive this by have a field which contains your "population" list. Then you can replace the options in the selection list.

Ad this to the hooks/footer-extras.php

Code: Select all

<?php
 $res = sql("SELECT ##VALUE## from ##TABLE##",$eo);
  		
 $newo = array();
 $newo[] = '';    // add empty entry at the top
					   
 while ($row = db_fetch_assoc($res)) {
	$newo[] = $row['##VALUE##'];
 }
		
?>
<script>
$j(function () {
  // Store your new options in an array
  var newOptions = <?php echo json_encode($newo); ?> ;

  // Clear out your current options
  $j("[id=##ID_OF_SELECTION_LIST##]").empty();
  
  // Add each new option to the element
  $j.each(newOptions, function(value,key) {
    // Create a new <option> appending the values and text and add it to the list
    $j("[id=##ID_OF_SELECTION_LIST##]").append($j("<option></option>").attr("value", value).text(key));
  });
  
});
</script>
Please replace

##VALUE## = Field which contains the values that will populate the multi-select
##TABLE## = Table containing your values
##ID_OF_SELECTION_LIST## = multi-select dropdown list

hope that helps
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: multi choice

Post by baudwalker » 2018-04-30 04:54

Sorry, pböttcher,

Just can't get my head around your "Please replace Items"
what I have...

table_one
id1 item as varchar
1 item1
2 item2
3 item3

table_two
id2 select_items as varchar
1 select1

Have table one as a selection in table two

##VALUE## = item
##TABLE## = table_one
##ID_OF_SELECTION_LIST## = select_items

is this what you mean? but it does not work :(

Barry

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: multi choice

Post by pbottcher » 2018-04-30 05:33

Hi Barry,


##ID_OF_SELECTION_LIST = HTML id of the dropdown list that was created by AppGini to store your selected values in.

you can use the Browser-debug mode to identify the correct ID given by AppGini.

What result do you get? Is your dropdown empty, or still filled with the old values?

In case it is has the old values you do not have the correct ##ID_OF_SELECTION_LIST##.

In case it is empty, the result from your $newo-array does not meet the json_encode requirements.

regards
Pascal
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: multi choice

Post by baudwalker » 2018-04-30 10:27

OK I have an empty result, nearly there:)

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: multi choice

Post by pbottcher » 2018-04-30 11:51

make sure your SQL-result conforms with the expected data for json-encode.
you can print

echo json_last_error()

to see if you get an error.

You may try to use utf8_encode.

json_encode( utf8_encode( $newo ) );
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

gatenet
Veteran Member
Posts: 45
Joined: 2016-07-26 09:34
Location: Greece
Contact:

Re: multi choice

Post by gatenet » 2018-05-04 15:58

I Have also requested from Appgini to be able to create a field that you need, Ahmad promised that will be there in the next update

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: multi choice

Post by baudwalker » 2018-05-07 00:02

great

landrea
Posts: 27
Joined: 2018-08-04 13:09

Re: multi choice

Post by landrea » 2018-08-04 16:27

i'm new user and still i'm studying the software

i was looking for a solution like the question of the topic
i'm intrested your solution,
so i ask help to get it better

i think i get the php file you posted

I create a specific table that i use for the list options
when someone update the table (for example insert something) i have a hook with php code that fire the script
the script make a query to the mysql and get all the values inside
then the script open the csv file and override all the values inside

at this point if I use somewhere the option list associated to the csv file i get the new values

what i dont understand well is how associate the option list to the csv file
because in app gini it seems i neet to write values separated by a double semicolon like this ;;

so do i need here to write the url or the name of csv?
i dont' get this point
i dont' get exactly what i need to write in place of the list separated by semicolon;;
also i need to setup it like blob or text?

in documentation i didnt find possibilty to use a csv file there,
so it's point not clear to me

thanks
Bertv wrote:
2018-04-27 15:36
You have to use a csv-file for the options.
optionlist.png
In the the table with the options you have to create the options csv file int the after insert and after update hook.
See below an example:

function adm_mail_groepen_after_insert($data, $memberInfo, &$args){
// stel de mailgroepenlijst t.b.v.mailingen opnieuw samen
$csvfile = "adm_mailingen.mln_mailgroep.csv";
// - stel de mailgroepenlijst opnieuw samen
$sql_string = "SELECT mgr_naam
FROM adm_mail_groepen";
$resultaat = sql($sql_string, $eo);
$num_rows = db_num_rows($resultaat);
$list = "";
if ($num_rows > 0) {
while ($rij = db_fetch_array($resultaat)) {
if(!$list) {
$list = $rij["mgr_naam"];
} else {
$list = $list . ";;" . $rij["mgr_naam"];
}
}
}
// - save de csv-file
$file = fopen("hooks/$csvfile", "w");
fwrite($file, $list);
fclose($file);

return TRUE;
}

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: multi choice

Post by pbottcher » 2018-08-04 18:30

Hi,

have a look at
http://bigprof.com/appgini/help/advanc ... ic-files So if you use a table to store the possible values for the option list. You need to retrieve the values from that table an put it in a string, separated with double semicolon and write it to the coresponding file of your option list.
In AppGini you can write whatever you want, as AppGini will use the content of the file if it exists and ignore the input of the settings in the GUI.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

landrea
Posts: 27
Joined: 2018-08-04 13:09

Re: multi choice

Post by landrea » 2018-08-06 12:54

Thanks

Yesterday i made some test

It's not important what you write in the app gini interface since if you put a csv file this ovverride simply your original list
(this behaviour is in the php code of root/tablename_dml.php)

csv file need the following name: table.field.csv and you need to put it into the hook folder
simply you use a combination of ;; for separate you values

At this point you need only to associate this file to a different table you use for this porpouse and add a php script hook that update the values of the csv file when something happen (like scritp posted by user Bertv)

Really it don't seem it work so hard to do

Surelly add this in the official features coudl be better because they can improve also a limit of choiches or other features (really this also coudl be accomplish with hook probably adding some javascritp function, i think to work about it, for limitating the number of choices allowed), but really, general speaking, it's not something hard to do

pböttcher wrote:
2018-08-04 18:30
Hi,

have a look at
http://bigprof.com/appgini/help/advanc ... ic-files So if you use a table to store the possible values for the option list. You need to retrieve the values from that table an put it in a string, separated with double semicolon and write it to the coresponding file of your option list.
In AppGini you can write whatever you want, as AppGini will use the content of the file if it exists and ignore the input of the settings in the GUI.

Post Reply