Welcome to the nuBuilder Forums!

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

Color rows doesn't work with Safari

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

Color rows doesn't work with Safari

Unread post by marcvander »

Hey,

I have had this JS running and working perfectly under Chrome browser:

Code: Select all

if (nuFormType() == 'browse') {

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = yyyy + '-' + mm + '-' + dd;

    $('[data-nu-column="0"]').each(function (index) {

        var cellId = $(this).attr('id');
        var cellValue = $('#' + cellId).html();
        var rowNum = String(cellId).split('_')[1];

        if (cellValue < today) {
            $("div[id^='nucell_" + rowNum).css("color", "red");
        }
        if (cellValue == today) {
            $("div[id^='nucell_" + rowNum).css("color", "green");
        }
    });
}
It basically colors in red if current date > date value in row, and in green if current date == date value in row.

It doesn't work under Safari browser. Here is the error I get in Safari console:
Error: Syntax error, unrecognized expression: div[id^='nucell_0 error jquery.js:1586

I guess the expression has to be stated differently for Safari, but how?

Thanks

Marc
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
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Color rows doesn't work with Safari

Unread post by kev1n »

Your syntax is incorrect. You're missing a ] so the error is correct. Chrome is lenient and closes the selector for you but Safari obviously doesn't.

Replace

Code: Select all

$("div[id^='nucell_" + rowNum).css("color", "red");
With

Code: Select all

$("div[id^='nucell_" + rowNum + "']").css("color", "red");
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Color rows doesn't work with Safari

Unread post by marcvander »

Ah damnit! Indeed it works now on Safari

Thanks :)
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: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Color rows doesn't work with Safari

Unread post by admin »

.
Locked