Validation - Working with Server Side Validation and Customising Validation Feedback

I’ve just spent some time looking at how to customise the world of input validation in Wappler. It was a bit of a journey, so I thought I’d document what I have discovered so far here to help others and get feedback which may enhance my knowledge!

Client Versus Server Validation

So validation can happen on the client side or the server side. On the client side, the feedback is instant, as the user types. On the server side, the validation occurs when the user clicks on a submit button.

There may be cases where you want one or the other. I’m creating an app that the same people will use day after day, and I don’t want them to be bombarded with messages all the time as they type the same things into the same inputs on a regular basis. In most cases I just want server side validation to remind them when they occasionally missed something out or entered it in the wrong format.

How to use the client side validation is well documented so I will focus more on setting up the server side only validation which I found more tricky to do.

Working With Server Side Validation

Here are the steps you need to make server side validation work:

  1. Server Side - specify which page and which form the server action is to be linked to by clicking on the Globals object:

  1. For each POST input, specify (a) the name of the input element that the message applies to in the Linked Field field and (b) the validation rule you require and the message you want to pass to the user.

  1. On the client side, ensure that (a) the form does not have the novalidate attribute set. and (b) there are no client side validations set.

Voila, you should get your server side validation message appearing on the client side.

Note that at the time of writing it is not possible to extract the server side message from the database, which you would need if you are designing a multi-lingual system for example. There is a feature request to add this.

Customising the input and message look and feel after validation.

If you haven’t got into the detail of designing your own bootstrap theme, you can use custom CSS to style the results of the validation. For example you may wish to hide the green ticks and red crosses in the input box if there isn’t room for them - I have this issue as parts of my app are financial and my input boxes need to be narrow at times.

Here is the CSS you will need (assuming your inputs have the form-control class):

/* Input element after being shown VALID */
.was-validated .form-control:valid, .form-control.is-valid {
background-image: none !important;
}

/* Input element after being shown INVALID */
.was-validated .form-control:invalid, .form-control.is-invalid {
background-image: none !important;
}

/* the error message produced by bootstrap (if not in a form control group) */
.invalid-feedback { }

And finally, here is the feature request for allowing the server side message to come from the database…
Server Side Validation - Allow Message to Come From Database

1 Like

If they enter valid values, why do they see messages? The only case where a message appears as you type that I’ve come across is the email validation, so this might appear:

image

… so the user would see the green borders for example, which seems helpful. I can see the red borders are not ideal.

I thought the main point of client-side validation was to be unobtrusive - it’s of no value security-wise.

1 Like

I share your opinion Tom, it’s a really bad UX practice to make people fill the data twice - once when they fill it wrong, then submit, then show the errors, then they fill the inputs again fixing the wrongly entered data.

I find the box going red and a red message coming up while I enter a value is really annoying.

My users know what an email address is… they just need the very occasional prompt when they accidentally get it wrong, not lots of red messages and borders every time they start typing…

… but I respect everyone’s perspective on this, and am in hope that everyone can respect mine too. I’m actually looking to give my users the best UX experience I can, given what I know about their background and the tasks they do with my app on a daily basis.

It’s always lovely to have some debate on here! :rocket:

Nobody says they don’t.
But if you fill your email in like my_email@sitecom instead of my_email@site.com you won’t notice this until you submit the form.
Same with confirm password fields, etc etc - i can list many cases where a simple typo can cause frustration with users.

I have mixed feelings with that. I’ve been searching for the perfect tool to validate forms forever and I’ve never found it.

Ideally it would be a node package that works both server and browser that contains a set of validators common for browser and server.

As forms would be defined in the views and therefore parsed by express there could be validation syncing.

From a UX perspective a user would get immediate feedback on what they are doing wrong as you mention @Teodor and @TomD while enforcing exactly the same set of rules on the server to make sure you have one single source of truth to improve security and DRY.

Right now if you really want to do the things right you need to add client validation(taking into account BS and HTML5 validations), you then have to add server validation and make sure you are consistent.

And finally you end with a UX nightmare. Because if you have both(and you should) and you pass client, but fail server you will get a nice red feedback until you submit again.

The user will get confused because first he saw that the form was being validated in real time, then he gets this error from the back-end and now even if he corrects, the message won’t disappear until resubmit.

So he ends up with a corrected form filled of red before submitting. Under normal circumstances he wouldn’t submit because it’s all red although the form is completely valid. That’s the definition of UX nightmare.

1 Like

That can be improved indeed. Maybe @patrick can look into it :wink:

1 Like

Is email the only case where there is an issue (and one I mentioned I had come across)? I haven’t noticed any other cases where messages appear prematurely or unnecessarily.

Would you expect this to happen more than rarely? (Obviously if you have Javascript turned off…)

I’m still exploring that, but I know there are some which I will be using from my limited research… so I will be using a mix of client side and server side depending on the form they are fill in.

Am trying to understand everything and get my ducks in a row before putting validation all over my design!

Several scenarios where I see that happening.

  1. I forget to add a client rule
  2. The constrain is different
  3. No JS
  4. Malicious user by-passing client validation

3 and 4 I don’t care.
3 because the app is not compatible with non js browsers
4 because giving a bad UX to a malicious user is a feature not a bug :smiley:

1 and 2 are pretty common if your app uses input forms extensively. Enough to make me want to avoid bug reports on that.

For this reason I use exclusively server validation. I want one source of truth.

I might take a look in the future at validator.js as you can use it in server and backend. But that would mean forgetting about Wappler’s current implementation and I find Wappler’s implementation very user friendly so I am reluctant.

Maybe validator.js is a library that @patrick can check in order to improve UX. There is even a middleware for express

Edit: Waiting for the team’s post where one of them says “we were actually looking into this library”.

1 Like

Sounds like a fab way of doing things…

So we really need something that gives both of us multi-lingual support for server side validation then! :slight_smile:

I would suggest you look into my i18next integration and a very small hack to make error messages translatable.

It means some rework but it also means you get all the functionality of i18next instead of relying on database. Database string storage is something from the 2000s :slight_smile:

1 Like

Would love to Jonas, but am too far down the database road to go back… I need to concentrate on getting the product out the door rather than make everything “perfect”!

You would be surprised to know how fast you could move from DB to i18next.

  1. Add code
  2. Export data from mysql to csv to json.
  3. Do a regex search for all your project files and replace your translation bindings to the custom formatter used in the integration.
  4. Profit

But I do understand your situation.

Just don’t go so far down the database road that you can never turn around. These type of decisions are exponentially harder to revert :slight_smile:

I don’t know how many languages you are planning to support in the future but some languages require solid i18n frameworks. (i.e. polish)

Polish retains the Old Slavic system of cases for nouns, pronouns, and adjectives. There are seven cases: nominative (mianownik), genitive (dopełniacz), dative (celownik), accusative (biernik), instrumental (narzędnik), locative (miejscownik), and vocative (wołacz).

Try that without an i18n framework :smiley:

Where is your translation data held then?

And which method is easiest if I want to create a user interface for non techies to do the translation?

I’ll search “i18n for plebs” on youtube over lunch! :crazy_face:

Files on server under VCS(i.e. GIT) of course. You don’t get version control if storing on database and you want version control for translation files.

I personally use Mozilla’s Project Fluent file format(extension .ftl) which has an extension for i18next because I use Pontoon software that takes advantage of that format.

But normally you would use i18next json format. To handle translations you would normally start with a tool like 18n-manager until you are ready to delegate that work to other people.

For that there are out there several tools that connect to VCS(repositories and provide with a wonderful UI to manage translations)

Mozilla Pontoon, weblate, zanata, etc Look for Open Source Translation Management System.

1 Like

Wow, another whole world of technology to explore!

Thanks Jonas!

So do you need to do a complete translation of every piece of text?

So for example if I’m doing en-GB to en-US, I don’t need to translate much… so my database has the concept of en-GB being a backup language to en-US. Hence for en-US, I only need to change content which has words like color/colour and all the rest comes from en-GB.

It means the translation doesn’t necessarily have to be 100% complete as the base language for most others will be en-GB… but could be es-ES for a language like Catalan.

i18next is ready to handle all that.

1 Like