Field Renderer No Longer Working

  • 1
  • Problem
  • Updated 3 years ago
This field renderer has been working well for us for a long time and now it isn't. I wonder if it is from a recent update?

//
var field = arguments[0],value = arguments[1];
var currentDate = new Date();
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
if (skuid.time.parseSFDate(value) <  currentDate) {
field.element.css({'min-height':'30px','color':'red'});
}
//

It is supposed to turn the text red if the date is in the past. The date just looks normal now, even though it is in the past.
Photo of Kaede Holland

Kaede Holland

  • 2,744 Points 2k badge 2x thumb
  • ¯\_(ツ)_/¯

Posted 3 years ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Kaede,

I added console.log to verify the logic and the values.  Everything is still processing correctly except the field.element.css.  It does not change the color of the text.

I have updated your code and swapped the field.element.css.  In this version you can see the pink background and the height of the field change, but the font color of the date remains black.

var params = arguments[0],	$ = skuid.$;
var field = arguments[0],value = arguments[1];
console.log('Field ->' + field);
console.log('Value ->' + value);
var currentDate = new Date();
console.log('Current Date' + currentDate);
console.log('parseddate -> '+skuid.time.parseSFDate(value) );
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
if (skuid.time.parseSFDate(value) <  currentDate) {
    console.log('if is true');
    
    //field.element.css({'min-height':'30px','color':'red'});
    field.element.css({'background-color':'pink','min-height':'100px','color':'white'}); 
}

Maybe Skuid can explain why this isn't working?

Thanks,

Bill
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hi Kaede/Bill -

The reason the color isn't changing is because Skuid is applying more specific styling to the children of the field.element.  For example, in the case of a field in 'read' mode, they are styling nx-fieldtext while in 'edit' mode they are styling the input/textarea/etc.  When CSS is processed, it always will take the most specific styling available falling back to parents for attributes where there isn't a more specific value provided.

To be honest, I'm not sure if this is a recent change or not but I wouldn't think it is.  It also could be somewhat theme specific - possibly you changed your theme recently?  Either way, if you modify your selector to the following, you should see the behavior you are looking for.  Also, the min-height won't achieve a larger font size.  Not sure if this is what you are after but using the font-size attribute will ensure the text itself is larger (assuming that is what you are after).

field.element.find('input, textarea, .nx-richtext-input, .nx-fieldtext').css({'font-size':'large','color':'red'});

As an alternative, you could use a css class to achieve your goal and then the custom renderer could just add the necessary class to field.element.  Something like the following:

JS
if (skuid.time.parseSFDate(value) <  currentDate) {    field.element.addClass('datewarning');
} else {
    field.element.removeClass('datewarning');
}
CSS
.nx-field.datewarning .nx-fieldtext,.nx-field.datewarning input, 
.nx-field.datewarning textarea, 
.nx-field.datewarning .nx-richtext-input {
    color: red;
    font-size: large;
}

Hope this helps!