Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Color a text on a subform object

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Locked
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Color a text on a subform object

Unread post 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?
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Color a text on a subform object

Unread post 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
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Color a text on a subform object

Unread post 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
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Color a text on a subform object

Unread post by admin »

Marc,

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

Steven
You do not have the required permissions to view the files attached to this post.
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Color a text on a subform object

Unread post 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?
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Color a text on a subform object

Unread post 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
You do not have the required permissions to view the files attached to this post.
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Color a text on a subform object

Unread post by marcvander »

It works, thanks Steven!
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Color a text on a subform object

Unread post by admin »

.
Locked