Validating Query String Filter Values

In this lesson, we'll learn how to use VineJS, AdonisJS' Validator, to validate the filter properties and values we have within our query string.

Published
May 06, 24
Duration
7m 24s

Developer & dog lover. I teach AdonisJS, a full-featured Node.js framework, at Adocasts where I publish weekly lessons. Professionally, I work with JavaScript, .NET, and SQL Server.

Adocasts

Burlington, KY

Get the Code

Download or explore the source code for this lesson on GitHub

Repository

Join The Discussion! (3 Comments)

Please sign in or sign up for free to join in on the dicussion.

  1. Commented 9 days ago

    I had a strange behavior, the movie index page search :

    • OK without a query filter

    • OK with an alphanumeric query filter

    • Fails after removing an existing query filter, showing the following error after the title input:

    The search field must contain only letters and numbers

    When the query filter is removed, the search field value becomes an empty string instead of undefined or null.

    To fix this behavior, add the following line after your import statements:

    vine.convertEmptyStringsToNull = true

    1

    Please sign in or sign up for free to reply

    1. Commented 9 days ago

      More info here:


      [Empty fields lead to empty strings](https://vinejs.dev/docs/html_forms_and_surprises#empty-fields-lead-to-empty-strings)


      Additionally, if you want to allow searching with a two-word string (e.g., 'the p'), update the validation pattern as follows:

      search: vine.string().alphaNumeric({ allowSpaces: true }).optional(),

      1

      Please sign in or sign up for free to reply

      1. Commented 6 days ago

        Terribly sorry about that adun! I'm happy to see you were able to figure it out, and your assessment is spot-on! I'll circle back and insert a heads-up into this lesson. Thank you very much for sharing, and sorry again this got past me!

        1

        Please sign in or sign up for free to reply