I know this is from over a year ago, but wondering if I can get some follow up.
I am creating a learning management system and I have 40+ modules with 1-5 Lessons in each module.
I used this post to put together code for one module that has 8 lessons within it. I have 8 detail views on one scene. Each detail view links to the relevant lesson and displays the status of that lesson (not stated, in process, complete, etc) - see attached image.
Now I can copy and paste this code snippet for each view that needs to reference it, but you mention be able to make it more dynamic so I can apply it to multiple views and field values…can you help me with this? for reference, here is the code for lesson 1, lesson 2, and lesson 3 and here is a snapshot of what it looks like on the scene. Note that in the code, the view ID changes AND the field ID.
/Change text color based on field value (Details View) - this is used in the modules lessons summary page
//normal pregnancy and prenatal care
//lesson one
$(document).on(‘knack-view-render.view_2344’, function (event, view, data) {
var $field = $(‘#view_2344 #kn-input-field_1377’)
var fieldValue = $field.text().trim()
if (fieldValue === ‘NOT STARTED’) {
$field.css(‘color’, ‘RED’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘IN PROGRESS’) {
$field.css(‘color’, ‘ORANGE’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘COMPLETE’) {
$field.css(‘color’, ‘GREEN’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘SUBMITTED’) {
$field.css(‘color’, ‘BLUE’)
$field.css(‘font-weight’,‘bold’)
}
})
//lesson two
$(document).on(‘knack-view-render.view_2357’, function (event, view, data) {
var $field = $(‘#view_2357 #kn-input-field_1378’)
var fieldValue = $field.text().trim()
if (fieldValue === ‘NOT STARTED’) {
$field.css(‘color’, ‘RED’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘IN PROGRESS’) {
$field.css(‘color’, ‘ORANGE’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘COMPLETE’) {
$field.css(‘color’, ‘GREEN’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘SUBMITTED’) {
$field.css(‘color’, ‘BLUE’)
$field.css(‘font-weight’,‘bold’)
}
})
//lesson 3
$(document).on(‘knack-view-render.view_2387’, function (event, view, data) {
var $field = $(‘#view_2387 #kn-input-field_1379’)
var fieldValue = $field.text().trim()
if (fieldValue === ‘NOT STARTED’) {
$field.css(‘color’, ‘RED’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘IN PROGRESS’) {
$field.css(‘color’, ‘ORANGE’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘COMPLETE’) {
$field.css(‘color’, ‘GREEN’)
$field.css(‘font-weight’,‘bold’)
}
if (fieldValue === ‘SUBMITTED’) {
$field.css(‘color’, ‘BLUE’)
$field.css(‘font-weight’,‘bold’)
}
})