Skip Navigation

[Resolved] view won't let me save with this code

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Ido Angel 4 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1838801

Hey,
I have this code for toggling "read more" and "read less" on elements which contain more than a certain number of characters:

var showChar = 250;  // How many characters are shown by default
    var ellipsestext = "...";
    var moretext = "+ קראו עוד";
    var lesstext = "- סגירה";
    
    jQuery('.offer-bottom').each(function() {
      var content = jQuery(this).html();
      if(content.length > showChar) {
        var c = content.substr(0, showChar);
        var h = content.substr(showChar, content.length - showChar);
        var html = c + "<span class='moreellipses'>" + ellipsestext + "</span><span class='morecontent'><span>" + h + "</span><a class='morelink'>" + moretext + "</a></span>";
       jQuery(this).html(html);
        }
    });
  
  jQuery(".morelink").click(function(){
        if(jQuery(this).hasClass("less")) {
            jQuery(this).removeClass("less");
            jQuery(this).html(moretext);
        } else {
            jQuery(this).addClass("less");
            jQuery(this).html(lesstext);
        }
      jQuery(this).closest(".offer-bottom").toggleClass("show-more-text");
        return false;
        
    });

It works well if I use it on document.ready - but I need it to work also after the results are updated (as I have an ajax search there), but when I try to save the code inside the

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {

});

function, the view just won't save and give an error - UNLESS I remove these 2 lines:

var c = content.substr(0, showChar);
 var h = content.substr(showChar, content.length - showChar);

hidden link (print screen of error)

I tried to debug these lines - but can't see anything wrong with them.
Any ideas?

Thanks!

#1839305

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ido,

We actually don't debug custom coding, however I placed this code in the JS editor of my view and it saved perfectly fine.

Can you try adding the code to a different view and let me know if the issue still remains ?

Perhaps something else is causing the view not to save.

Thanks,
Shane

#1839323

Thx Shane!
No - I tried with another view, and it keeps not saving the view the code is in.
However in a new install of a fresh site - it does save.
So strange..

#1839391

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ido,

Would you mind allowing me to have a quick look at the site itself?

Perhaps I can sport something.

I've enabled the private fields for your next response.

Thanks,
Shane

#1839393

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Private fields

#1839395

thx shane, ur the best!

#1840063

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2020-11-10 at 9.34.54 AM.png

Hi Ido,

Unfortunately I cannot see nothing wrong with this content apart from the request being blocked when trying to save when the substr() function is used on this particular view.

Here is the error, see screenshot.

What I would do is to perhaps remake the view and add the code to that new view given that it works on other views.

Thanks,
Shane

#1840261

Thanks Shane
I think it must be a php issue - I switched servers and suddenly all is well
Cheers
Ido