add style to individual <li> element shown from another table

Status
Not open for further replies.

dangdesigns

New Member
I have a field in (form1) that I need to change the color of the text that is inside the <li> element shown in the form list (form2) list view.

The color of the text needs to based on a another field from the form1.

tableForm1
- fieldtoshow
- color
- someotherfieldnotrelated
...

Form2
- colortest (databasejoin to form1.fieldtoshow)
- otherfields

I've made the example above generic, here's a visual also.
Am I using the correct tool with databasejoin?
I don't see any way to add css to the <li>element itself, only the row (which is in use in the visual sample)

what it is now:
Color_Test-current.jpg

What I need it to be:
Color_Test-2.jpg .
 
Last edited:
So you've set your databasejoin element to "use as rowclass" and added the colors to your custom_css.php with something like
tr.your-colortest-value1 {background:red;}
tr.your-colortest-value2 {background:yellow;}
?
If you want to set only the background of one element in the row add something like
tr.your-colortest-value td.your-full-elementname {background:red;}
 
Perhaps my post wasn't clear. I need to change the text color (not background) of the individual elements, with several different colors, in the <td> based on the field "color" in table1. I see the list is generated as a <ul><li>..</li></ul> I need to add a css style "color: #whatever;" to the <li>...

The row color is in use, but unrelated to the change I need to make here. I probably should have left that info off.
 
Last edited:
I think you can use the "or concat label" setting in the dbjoin element (I didn't test):
'<span class="' , {thistable}.color , '">' , {thistable}.fieldtoshow , '</span>'

Which will give you
<ul><li><span class="xy">full name</span></li></ul>
 
That would probably cause issues in the join's select on the form itself, as I'm pretty sure select options can't contain any HTML tags. I can't remember if they just get stripped, or shown as part of the option text.

-- hugh
 
Hmm, I just tested:
It seems to be working; it's adding the span in list and details view and ignoring/stripping it in the dropdown select in form view (but maybe not a "clean" solution).
 
Hmm, I just tested:
It seems to be working; it's adding the span in list and details view and ignoring/stripping it in the dropdown select in form view (but maybe not a "clean" solution).

Yeah, I just couldn't remember if it strips the markup or not. If it does just strip it, then it should be a workable solution.

-- hugh
 
unfortunately this doesn't work for my set up, I get an error when I enter anything (I tried numerous items) into the Concat label field.

example

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`,
`table2_66_repeat`.`otherfields` AS `table2_66_repeat___otherfields`,' at line 32
 
looks like it might be something with the ' vs `
I can use {thistable}.type_user,{thistable}.name without error,
php version 7.1 (I can change if necessary)
 
weird, I used the singles first and got an error, must have missed one. All good now, working as expected.
Again, thank you.
 
Just to complete this thread ... in MySQL, backticks are only used for table and field names. They aren't compulsory, but are a good habit, in case you have any field names which also happen to be MySQL reserved words. So for example if you had a field called "check", using it without `check` backticks would cause an error.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top