Validating Query String Filter Values
We'll learn how to use VineJS, AdonisJS' Validator, to validate the filter properties and values we have within our query string.
- Created by
- @tomgobich
- Published
- Last updated
Join the Discussion 3 comments
-
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 numbersWhen the query filter is removed, the search field value becomes an empty string instead of
undefinedornull.To fix this behavior, add the following line after your import statements:
vine.convertEmptyStringsToNull = true1-
Responding to adun
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-
Responding to adun
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
-