Styled formula background
Having some trouble wrapping my head around how to use styled on a formula.
I have a yes/no field (Flag Account). If it is unchecked, I want the formula to just use the style I've set in the formula options. If Flag Account is checked, I want the background to be red (but the txt colour and border to stay the same).
Is that possible?
10 replies
-
https://ninoxdb.de/en/forum/technical-help-5ab8fe445fe2b42b7dd39ee7/styled-5d4d2eb4f766c72ea3c980b3
There are many other examples on the forum as well.
-
Thanks Sean. I'd seen that thread previously but looks like I needed to study it after a nights sleep so it would make sense.
Using that formula now, but having an issue where my line break is no longer working. The formula field is 3 spaces high so I was using a line break to vertically center the text. Now, no line break.
let displayText := "
" + Name;
let displayIcon := "";
let displayColor := "#fff";
let displayBackground := "#555";
if 'Flag Account' = true then
displayText := "
" + Name;
displayIcon := "warn2";
displayBackground := "#FF0000";
displayColor := "#fff"
else
if 'Flag Account' = false then
displayText := "
" + Name;
displayIcon := "";
displayBackground := "#555";
displayColor := "#fff"
end
end;
styled(displayText, displayBackground, displayColor, displayIcon) -
Sarah, yeah you're right. The only way I know of to do what you want is to use the html() function, but it will only display properly in form view. If table view is not a priorty and you are comfortable with HTML, you might want to try that.
-
Hi Sean
Familiar with HTML but a little unsure about implementing it with Ninox
Would it be a matter of doing a "if 'Flag Account' = true then
html("
<div style=""csshere"">"" + Name</div>
") -
Sarah, You can do it that way or build an HTML string and assign it to a variable like...
let htmlString := "HTML goes here"
and add to it...
htmlString := htmlString + "more HTML"
until you're ready to do this
html(htmlString)
at the end of the formula. Also, the result won't fill the entire formula field so you can set the background of the formula field to rgb(238, 238, 238) or #EEEEEE in the "Style" setting of the formula field to match the Form background.
-
Have you tried this already?
styled(yourformula,if 'Flag Account' then "red" end)
-
“Using that formula now, but having an issue where my line break is no longer working. The formula field is 3 spaces high so I was using a line break to vertically center the text. Now, no line break.”
-
I see, it's a strange behaviour when you use style the line break goes away. Maybe a bug? I would make 2 different formula fields and not using styled() but use a unicode icon instead for the second field.(use the style settings of the field itself to make it red) Then use the yes/no field to hide one of the two and vice versa.
formula 1:"
" + name
formula 2 :
+"
" + name
and style this formula field in the field settings red.
-
Oops formula 2 should be :
"
" + name
-
Steven, Good point about using a yes/no field to alternate between the two and it would keep the display consistent whereas the HTML method would be a little different than the rest of the fields.
I don't know if it's a bug or not, but it's strange that Option+Space is allowed and Option+Return isn't.
Content aside
- 5 yrs agoLast active
- 10Replies
- 4138Views