Skip Navigation

[Résolu] view won't let me save with this code

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Marqué : 

This topic contains 7 réponses, has 2 voix.

Last updated by Ido Angel Il y a 10 mois et 1 semaine.

Assigned support staff: Shane.

Auteur
Publications
#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: Anglais (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: Anglais (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: Anglais (English )

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

Private fields

#1839395

thx shane, ur the best!

#1840063

Shane
Supporter

Languages: Anglais (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