Icon in field depending on another field value

  • 0
  • 2
  • Question
  • Updated 2 years ago
  • Answered
HI all, newbie question here, and something i cannot figure out.
I want to create a new field, but have it show a icon. But the icon will be different depending on another field for that entry. for example;

Field1                        Field2              
red                            shows image from example url1 https://images.url.com/red.png
blue                            shows image from example url2 https://images.url.com/blue.png
green                          shows image from example url3 https://images.url.com/green.png

So when looking at the first line, the field2 will show a red icon, as the field1 text matches 'red'

hope that makes sense, thanks.
Photo of ChrisRyanUk

ChrisRyanUk

  • 120 Points 100 badge 2x thumb

Posted 2 years ago

  • 0
  • 2
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
HI Chris,

Please create a formula text field and turn on the Allow some HTML tags to be inserted option in the field.

Use this formula:

Case([Field1],"red", "<img src=\"https://images.quickbase.com/si/16/227-rect_red.png\"; title=\"red\">", 
"blue", "<img src=\"https://images.quickbase.com/si/16/230-rect_blue.png\"; title=\"blue\">",
"green","<img src=\"https://images.quickbase.com/si/16/228-rect_green.png\"; title=\"green\">")

Please let me know if you need any further help.

Thanks,
Gaurav
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,624 Points 20k badge 2x thumb
Get in the habit of putting formulas within a <pre> tag:
Case([Field1],
  "red", "<img src=\"https://images.quickbase.com/si/16/227-rect_red.png\"; title=\"red\">", 
"blue", "<img src=\"https://images.quickbase.com/si/16/230-rect_blue.png\"; title=\"blue\">",
"green","<img src=\"https://images.quickbase.com/si/16/228-rect_green.png\"; title=\"green\">" )
(Edited)
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
Thanks Dan, I'll make sure next time :)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,624 Points 20k badge 2x thumb
The forum will not let me edit my prior post (this is really annoying) but I intended to replace the escaped double quotes with single quotes and remove the errant semicolon in the formula. Let me try again:
Case([Field1],
  "red",  "<img src='https://images.quickbase.com/si/16/227-rect_red.png' title='red'>", 
  "blue", "<img src='https://images.quickbase.com/si/16/230-rect_blue.png' title='blue'>",
  "green","<img src='https://images.quickbase.com/si/16/228-rect_green.png' title='green'>"
)
As well as post a version that does not even use single quotes on the attributes:
Case([Field1],
  "red",  "<img src=https://images.quickbase.com/si/16/227-rect_red.png title=red>", 
  "blue", "<img src=https://images.quickbase.com/si/16/230-rect_blue.png title=blue>",
  "green","<img src=https://images.quickbase.com/si/16/228-rect_green.png title=green>"
)

FWIW, because I placed these formulas within <pre> tags I have some scripts that can automatically extract formulas posted to the forum and place them into a formula corpus application. When you start looking at 1000s of QuickBase formulas in a table rather than working with formulas individually a lot of patterns emerge which helps understand the characteristics of good and bad formulas. Perhaps a byproduct of this effort will be to write up a best practices for constructing and formatting formulas.
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
Thanks Dan for this and I also tried to edit my previous post but could not able to do that. It is very annoying. Why have they done like this?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 59,838 Points 50k badge 2x thumb
I think the ability to edit may depend if you are signed in?  It seems to me that if I click that sign in button then I am able to edit my posts.  But I'm not 100% sure of that theory that it's simply forgetting to maintain my sign-on and that an extra click to get re-signed on will allow edits. 
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,624 Points 20k badge 2x thumb
I think it is rather obvious that the forum managers are hellbent on thwarting our efforts and that they should be sent to re-education camps.
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,882 Points 5k badge 2x thumb
Mark: No, I am not able to edit my post if I am already signed in and Dan is right "they should be sent to re-education camps." :-D  :-D
Photo of Matthew Neil

Matthew Neil

  • 31,638 Points 20k badge 2x thumb
I've noticed that once somebody else comments, your "Edit" ability goes away.  At least on my end.
Photo of ChrisRyanUk

ChrisRyanUk

  • 120 Points 100 badge 2x thumb
thanks both, i will give that a try and update you. much appreciated.
Photo of ChrisRyanUk

ChrisRyanUk

  • 120 Points 100 badge 2x thumb
worked brilliantly, thanks both.
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,880 Points 5k badge 2x thumb
Great :)