DropDown List different colors

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
mskuodas
Posts: 22
Joined: 2018-12-16 19:53
Location: Lithuania
Contact:

DropDown List different colors

Post by mskuodas » 2018-12-25 22:02

Hello, all,
I have DropDown list with for example options:
Yes;
No;
How to make them different colors? Not default black.
Yes - green
No - red.
Thanks

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 638
Joined: 2018-04-01 10:12

Re: DropDown List different colors

Post by pböttcher » 2018-12-31 11:18

Hi,

you can try this in the hooks/<tablename>-dv.js:

Assuming your selection is "empty, yes, no" otherwise you need to adjust the below code accordingly.
Replace YOURSELECTNAME by your selection.

Code: Select all

$j(function () {

	 var onSelectOpen=function(){ 
		 $j(".select2-drop-active .select2-result-selectable:eq(0)").css("color","")
		 $j(".select2-drop-active .select2-result-selectable:eq(1)").css("color","green")
		 $j(".select2-drop-active .select2-result-selectable:eq(2)").css("color","red")		 
	}
	 
	 var onSelectClose=function(){ 
		var myval=$j("#YOURSELECTNAME").val();
		switch(myval) {
			case "yes":
				$j("#s2id_YOURSELECTNAME .select2-choice").css("color","green")
			break;
			case "no":
				$j("#s2id_YOURSELECTNAME .select2-choice").css("color","red")
			break;
			default:
				$j("#s2id_YOURSELECTNAME .select2-choice").css("color","")
		}
	 }
	 
	 $j("#YOURSELECTNAME").on("select2-open", onSelectOpen);
	 $j("#YOURSELECTNAME").on("select2-close", onSelectClose);	 
}

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 265
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: DropDown List different colors

Post by jsetzer » 2018-12-31 14:53

Hi,

are you using a DropDown List from Options list-tab or a Lookup field?

I usually create additional (lookup-) tables and then use lookup fields in my master table. I sometimes even do if there is only Yes and No options. Then I populate the lookup-table with the required options and format the name-column (or an additional 'label' column, as I name it) the way I want to, for example:

chrome_2018-12-31_15-41-25.png
chrome_2018-12-31_15-41-25.png (29.75 KiB) Viewed 1194 times

You can play around with HTML as you like:

chrome_2018-12-31_15-42-51.png
chrome_2018-12-31_15-42-51.png (11.41 KiB) Viewed 1194 times

Kind Regards,
Jan

PS: Appy new year, everyone!

mskuodas
Posts: 22
Joined: 2018-12-16 19:53
Location: Lithuania
Contact:

Re: DropDown List different colors

Post by mskuodas » 2019-01-01 18:54

Hello, pböttcher and jsetzer, Happy new Year !
And thank you for your help :)
I have options list dropbox with Just two options Yes and No.
They must be changed after event. For example if member is in track - He is Yes (Green), if member is not on track, he's No (Red).
I tried to write .JS as pböttcher gave to me, but didnt work. I made name-dv.js , placed code and changed YOURSELECTNAME to my field name, where is these options, but im not sure if I did well ? And how to activate that .JS ? Is it automaticly used, when placed in hooks folder, and named table-dv.js ? or I should place some another code to some other php file ?
Thanks

sjohn
Veteran Member
Posts: 85
Joined: 2018-05-23 09:32

Re: DropDown List different colors

Post by sjohn » 2019-01-02 12:46

Hello mskuodas

Provided I understand the "problem" I have a simple solution, that requires no code at all.

Create a lookup table. In this lookup table make a field defined as a rich-text field.
In the field you can then have an image and/or some colored text.

In the table where you want the lookup shown, choose this field as the caption-field.
This way you will see the color when selecting, but also after the selection. The image and/or the text will be what is shown in the table-view and/or the datail-view.

If you want another field to be colored dependend of the choice for the lookup, I think it requires code, and I cannot be of any help then.

mskuodas
Posts: 22
Joined: 2018-12-16 19:53
Location: Lithuania
Contact:

Re: DropDown List different colors

Post by mskuodas » 2019-01-08 17:26

Well, sjohn :) it worked perfectly :) Good idea :) I'm improved now :D Thanks

xbox2007
Posts: 29
Joined: 2016-12-16 16:49

Re: DropDown List different colors

Post by xbox2007 » 2019-01-13 14:59

very nice ,

thanks a lot

onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 329
Joined: 2019-05-21 22:42
Contact:

Re: DropDown List different colors

Post by onoehring » 2019-07-05 09:58

Hi,

I get in line for saying thanks here. What a nice "side"-feature of AG.

Olaf

Post Reply