I am trying to display text color change in a text box based on conditional formatting in a repeater. I have queried my dataset based upon 4 possible options in a data field named “work”. I am able to capture the particular value for “work” based upon how a record is created, ie. “work” that needs to be done refinish, weld, straightening etc.
Based upon the query I extracted a record which is query results as an array. I have accessed the array value for “work” and I can console log the value for “work” and it works fine. From there I created if else if statements to format my text box in my repeater based upon the type of work that needs to be done.
What I found, though I am not really surprised is every time the format changes based upon the results of the query it changes all the format for existing records. Anyone have any suggestions. I know that the issue is a repeater text box isn’t unique to a record as it is unique to the repeater.
Here is my code:
import wixData from ‘wix-data’;
wixData.query(‘Orders’)
.contains(“work”, “Refinish”)
.or(
wixData.query(‘Orders’)
.contains(“work”, “Straightening”)
)
.or(
wixData.query(‘Orders’)
.contains(“work”, “Weld”)
)
.or(
wixData.query(‘Orders’)
.contains(“work”, “Weld & Straightening”)
)
.find()
.then((results) => {
if(results.items.length > 0) {
let items = results.items;
let a = items[0].work
if(a === “Refinish”) {
$w(“#text10”).html = ‘
’ + $w(“#text10”).text +‘
’} else if(a === “Straightening”) {
$w(“#text10”).html = ‘
’ + $w(“#text12”).text +‘
’} else if (a === “Weld”) {
$w(“#text10”).html = ‘
’ + $w(“#text13”).text +‘
’} else if (a === “Weld & Straightening”){
$w(“#text10”).html = ‘
’ + $w(“#text14”).text +‘
’}
console.log(a);
}
})