The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Word limit bug

2 posters

Go down

In progress Word limit bug

Post by Rhino.Freak March 10th 2014, 6:50 am

tutorial given here makes mobile users unable to post, the send button doesnt enable

https://help.forumotion.com/t131191-add-a-word-counter-to-the-editor

any fix?
Rhino.Freak
Rhino.Freak
Helper
Helper

Male Posts : 1248
Reputation : 104
Language : English
Location : Mumbai, India

http://freetest.forumotion.net/

Back to top Go down

In progress Re: Word limit bug

Post by Ange Tuteur March 10th 2014, 7:18 am

I'm not sure what mobile devices they're using, but you can try this :
Code:
$(function(){
    if (window.innerWidth > 480) {
    $(function(){

           var MinNumberOfWords = 5;
           var LetterCountPerWord = 3;
           var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
           var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";  
      
        if($("#text_editor_textarea").length != 0){
              $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");      
              $(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
              
              var sceditor = $("#text_editor_textarea").sceditor("instance");                  
              var str = sceditor.val();
              var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
              var str_arr = str.match(regex);
              var str_len = str_arr == null ? 0 : str_arr.length;
              
              if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
              
              sceditor.keyUp(function(e) {
                 str = sceditor.val();
                 str_arr = str.match(regex);
                 str_len = str_arr == null ? 0 : str_arr.length;
                 if(str_len >= MinNumberOfWords) {
                    $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl  + "' />");  
                $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
                 }else{
                    $("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl  + "' />");
                    $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
                 }
              });
           }
        });
    }
});

Replace your old script with the above. It will only run if the users inner width is greater than 480.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum