Hello @sakis11111
Thank you so much for using our plugin. Yes, that’s possible, but requires a calculated field as an auxiliary.
Assuming your fields are fieldname1, fieldname2, and fieldname3.
Insert a calculated field to use as an auxiliary. You can exclude it from the submission and hide it from the form by ticking a pair of checkboxes in its settings.
Finally, enter the following equation:
(function(){
let fields = {
fieldname1|n: fieldname1,
fieldname2|n: fieldname2,
fieldname3|n: fieldname3
},
color;
for(let i in fields) {
if(fields[i] < 50 ) color = 'green';
else if(fields[i] < 80 ) color = 'orange';
else color = 'red';
getField(i).jQueryRef().find('input').css('color', color);
}
})()
Note I used hypothetical fields’ names, values, and colors. You must replace them with the preferred ones.
Also, note I included the |n modifier in the piece of code:
let fields = {
fieldname1|n: fieldname1,
fieldname2|n: fieldname2,
fieldname3|n: fieldname3
},
It tells the plugin you are referring to the field’s name and not its value. The previous code creates an object with pairs, fields’ names and values.
Best regards.
I am very impressed by your so fast answer!
This partially solved my issue. Maybe I didnt described it well 🙂
Your code works fantastic but it changes the color of the values. What I need to do is this to change the color of the field box. But not just change it in general. I know how to do that. I need to fill the field with color, according to the value I put. If for example the value I put is 50, then the field fiils with color by its half. The rest of the half remains white. The same must happen to the calculated field 🙂
-
This reply was modified 11 months, 4 weeks ago by
sakis11111.
-
This reply was modified 11 months, 4 weeks ago by
sakis11111.
Hello @sakis11111
That requires a more complex CSS rule. Assuming the fields’ values go from 0 to 100, you can edit the equation as follows to apply a gradient in the field’s background:
(function () {
let fields = {
fieldname1|n: fieldname1,
fieldname2|n: fieldname2,
fieldname3|n: fieldname3
};
for (let i in fields) {
getField(i).jQueryRef().find('input').css('background', 'linear-gradient(to right, green 0%, green ' + fields[i] + '%, white ' + fields[i] + '%, white 100%)');
}
})()
Best regards.
Once more I am very impressed by your very fast answer and your willing to help. Your code works flawless, thank you !