Support » Plugin: TablePress » Setting a minimum character limit for search

  • Resolved azizpbrimah

    (@azizpbrimah)


    Is there a way to make a minimum character limit for the search box? For example, making it that no results are returned unless the 3 or more characters are input. This would prevent results returning/showing for only 1 or 2 characters having been input. Please advise. Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    I see what you mean, but unfortunately, I’m not aware of a solution for that, sorry.

    Regards,
    Tobias

    Thanks. Do you think this is something that can be implemented in the future?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    if so, it would not be directly in TablePress, but would have to be in the external DataTables JavaScript library that TablePress uses. It’s not impossible, but I don’t know how big the chances are. Sorry.

    Regards,
    Tobias

    No worries. Hopefully someone else will need this kind of functionality (or may have already needed it, couldn’t find it) and will figure it out. Thanks, again.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yes, that would be nice! We’ll have to be patient…

    Best wishes,
    Tobias

    azizpbrimah

    (@azizpbrimah)

    Okay, perhaps there is another angle that can be taken…. I am using the DataTables Inverted Filter extension, and it is obviously showing results based off of character matching. Is there no way to extend the extension so that it only shows things when there are three (or a certain number of) characters?

    We are trying to keep people from just typing one letter and being able to view names within our directory.

    LINK: http://www.bennett.edu/directory

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    If you are using the Inverted Filter Extension, you could indeed modify it to check the length of the search term, before showing the table. With that, the filtering would still be done in the background, but it would not be shown.
    For this, please try changing the line

    $( '.dataTables_wrapper' ).find( '.tablepress' ).toggle( '' !== $( this ).val() );
    

    to

    $( '.dataTables_wrapper' ).find( '.tablepress' ).toggle( $( this ).val().length > 3 );
    

    Note however that this is only cosmetics and nothing secure at all. A visitor could simply turn off JavaScript in the browser or inspect the source code of the HTML page in the browser and he would be seeing all data of your directory.

    Regards,
    Tobias

    azizpbrimah

    (@azizpbrimah)

    Works perfectly! Thanks so much!

    azizpbrimah

    (@azizpbrimah)

    By the way, I am aware that this is only a cosmetic fix at the moment. We’ve been using TablePress for the directory for over three years now. Until we find another solution, this will have to do. Thanks again!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    azizpbrimah

    (@azizpbrimah)

    Consider it done!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks, I really appreciate it!

    Best wishes,
    Tobias

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.