Required minimum characters

  • Tamas
    Tamas
    Newbie 7 points
    August 11, 2013 at 2:08 pm

    The admin would be able to set a minimum number of characters in the description field. If it is set to, say 300, and the user provides only 250 characters, the submission would be rejected.

    You can also vote for this feature on the feature request board here: https://ideas.premiumpress.com/idea/required-minimum-number-of-characters/

  • adrian
    adrian
    Newbie 32 points
    February 5, 2014 at 11:04 am

    this ideea is great , and will resolve a lot of problems … vote for it

  • patrik
    patrik
    Newbie 49 points
    March 13, 2015 at 8:53 am

    so? no go?

  • M
    M
    Senior Member 278 points
    March 15, 2015 at 2:19 am

    Here’s a basic script to try :

    Place in to your Design setup -> Custom Meta Data -> Footer Styles
    [code title=””]
    <script>
    var minLength = ‘300’;
    jQuery( “#MainSaveBtn” ).click(function() {
    var curLength = jQuery(“textarea#form_post_content, div#nicEdit-main”).val().length;
    if( curLength < minLength ) {
    alert(“Please enter “+minLength+” or more characters for your description”);
    }
    });
    </script>[/code]

  • M
    M
    Senior Member 278 points
    March 15, 2015 at 3:42 am

    You could also write something like this:

    [code title=””]
    alert(“Please enter “+minLength+” or more characters for your description. \r\nCurrently using “+curLength+””);[/code]

    Which would read:

    Please enter 300 or more characters for your description.

    Currently using 153

  • Juan Carlos
    Juan Carlos
    Newbie 13 points
    April 1, 2015 at 7:37 pm

    This is a great solution M. But the listing still gets published if the user clicks on Publish, no matter the alert. Do you know how to prevent users from publishing if they don’t enter the required minimum lenght?

  • M
    M
    Senior Member 278 points
    April 1, 2015 at 8:14 pm

    Try adding e.preventDefault(); like this….

    [code title=””]<script>
    var minLength = ‘300’;
    jQuery( “#MainSaveBtn” ).click(function(e) {
    var curLength = jQuery(“textarea#form_post_content, div#nicEdit-main”).val().length;
    if( curLength < minLength ) {
    e.preventDefault();
    alert(“Please enter “+minLength+” or more characters for your description”);
    }
    });
    </script>[/code]

    I can’t test this right now… so let me know if its ok or not…

  • Juan Carlos
    Juan Carlos
    Newbie 13 points
    April 1, 2015 at 8:56 pm

    It worked perfectly! Thanks a lot, M. I just added a code I found at tpl-add.php so that it takes users to the required field and expands the collapsible panel.

    <script>
    var descripcion = document.getElementById("form_post_content");
    var minLength = '300';
    jQuery( "#MainSaveBtn" ).click(function(e) {
    var curLength = jQuery("textarea#form_post_content, div#nicEdit-main").val().length;
    if( curLength < minLength ) {
    e.preventDefault();
    alert("Please enter "+minLength+" or more characters for your description. \r\nCurrently using "+curLength+"");
    descripcion.style.border = 'thin solid red';
    descripcion.focus();
    colAll(); jQuery('.stepblock2').collapse('show');
    }
    });
    </script>

Viewing 8 posts - 1 through 8 (of 8 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes