Page 1 of 1

Color a text on a subform object

Posted: Tue Oct 23, 2018 4:13 pm
by marcvander
Hey,

i'm trying to color a text on a subform object. I've already managed to do it on a browse form:
Capture d’écran 2018-10-23 à 16.07.05.png
The code to do it:

Code: Select all

if (nuFormType() == 'browse') {
    
    $('[data-nu-column="8"]').each(function (index) {
    
        var cellId = $(this).attr('id');
        var cellValue = $('#' + cellId).html();
        var rowNum = String(cellId).split('_')[1];
    
        if (cellValue === "1") {
            $("div[id^='nucell_" + rowNum).css("color", "blue");
        }
        else {
             
        }
    });
}
(I've hidden the column number 8 on the browse form, it is just to get the value to color the right rows).

Now I'm trying to do the same on a subform display object. I've tried to add this custom js code on the subform display object:

Event: onload
JS:

Code: Select all

if ($('#contact_plus_la') === "1") {
    $('#contact_nom').css("color", "blue");
}
But it doesn't get colored. Maybe the Event "onload" is not proper? Or maybe it doesn't know which #contact_nom to color? Any idea?

Re: Color a text on a subform object

Posted: Wed Oct 24, 2018 2:27 am
by admin
Mark,

You could use something like this - once you know the row you want to change...

Code: Select all


function color_subform_row(subform_name, row){

    $('#' + subform_name + nuPad3(row) + 'nuRECORD').children().each(function (index) {
    
        var f = nuSubformObject('zzzzsys_browse_sf').fields;
        
        for(var i = 1 ; i < f.length - 1 ; i++){                                              //-- ignore the first and last fields
            $('#' + subform_name + nuPad3(row) + f[i]).css('color', 'blue');
        }
        
    });
    
}


Steven

Re: Color a text on a subform object

Posted: Wed Oct 24, 2018 9:42 am
by marcvander
Hey Steven,

thanks for the reply. I tried to execute your function in the browser console, and here is the error I get:
Capture d’écran 2018-10-24 à 09.40.38.png

Re: Color a text on a subform object

Posted: Wed Oct 24, 2018 10:05 pm
by admin
Marc,

Is your first parameter a string - and the name (ID) of the Subform?
bsf.PNG

Steven

Re: Color a text on a subform object

Posted: Fri Oct 26, 2018 11:06 am
by marcvander
Steven,

I forgot to replace this line in the function:

Code: Select all

var f = nuSubformObject('zzzzsys_browse_sf').fields;
with my own subform id. So now that works, I manage to call the function in my browser and color a row like that:

Code: Select all

color_subform_row('subformcontactentreprise', 2)
Now I would like the rows which match a certain condition (in my case value === "1") to be colored with that function.

Here is my function:

Code: Select all

if (nuFormType() == 'edit') {
    
    $('[data-nu-column="2"]').each(function (index) {
    
        var cellId = $(this).attr('id');
        var cellValue = $('#' + cellId).html();
        var rowNum = String(cellId).split('_')[1];
    
        if (cellValue === "1") {
            color_subform_row('subformcontactentreprise', rowNum)
        }
        else {
             
        }
    });
}
The issue is that when I place it in the main form custom code, or on the subform object custom code with an onload event, nothing happens. I guess that if I want to place it in the main form custom code, I would need to add something to tell I'm looking for column n°2 in a particular subform. The change would be needed here:

Code: Select all

$('[data-nu-column="2"]').each(function (index) {
I tried something like:

Code: Select all

$('#subformcontactentreprise').$('[data-nu-column="2"]').each(function (index) {
But doesn't work

Any idea?

Re: Color a text on a subform object

Posted: Mon Oct 29, 2018 1:45 am
by admin
marcvander,

Try putting this in the Javascript part of your Form...

Code: Select all



loop_subform();        //-- this will run everytime the Form is loaded

function loop_subform(){

    
    $("[id^='zzzzsys_browse_sf'] [id$='nuRECORD']").each(function (index) {
    
		var p	= '#zzzzsys_browse_sf' + nuPad3(index);
    
        if ($(p + 'sbr_order').val() == "10") {
            color_subform_row('zzzzsys_browse_sf', index)
        }
		
    });


}


function color_subform_row(subform_name, row){

    $('#' + subform_name + nuPad3(row) + 'nuRECORD').children().each(function (index) {
    
        var f = nuSubformObject('zzzzsys_browse_sf').fields;
        
        for(var i = 1 ; i < f.length - 1 ; i++){                                              //-- ignore the first and last fields
            $('#' + subform_name + nuPad3(row) + f[i]).css('color', 'blue');
        }
        
    });
    
}


//-- this will check everytime the field values change
ai.PNG

Steven

Re: Color a text on a subform object

Posted: Mon Oct 29, 2018 10:31 am
by marcvander
It works, thanks Steven!

Re: Color a text on a subform object

Posted: Mon Oct 29, 2018 9:21 pm
by admin
.