Thursday, July 25, 2013

Simplifying the list of data types in Form Builder

Form builder always had the ability to validate data using data types such as "string", "integer", "decimal", "date", "email", and so on.

Most (but not quite all) of the types available in Form Builder until now come from an XML specification called "XML Schema". When we first implemented this feature in form builder many years ago, we simply took the list of types from that specification!

The problem is that many, in fact most of the types in that list don't make much sense for end users, with names such as "NMTOKENS" that even programmers have trouble figuring out.

What we had done initially to alleviate that was to try to put the most common types at the top. But for Orbeon Forms 4.3, we took a closer look at this and did the right thing: remove all the unneeded types (see the screenshot for the new list).

We have for now kept the few variants on the "integer" type, such as "Positive Integer". These are convenient, although they should be available for all number types, not only integers.

While doing this we have also thought about the "double" number type. The problem with this data type is that it is represented by software in binary form, and that the numbers entered by users are decimal numbers. When converting from one type to the other, there is often a loss of information, which becomes particularly visible when numbers are for example added together.

It is in fact very rare outside of scientific work to need doubles, and you should generally use decimal numbers instead. We have reflected this in Form Builder by putting the decimal type at the top and the double type at the bottom, and we might even remove it altogether in the future.

Wednesday, July 17, 2013

Enhanced validation in Form Builder and Form Runner

A major new feature of the upcoming Orbeon Forms 4.3 is enhanced validation. Up to 4.2, you could validate a control value with:
  • whether a value is required
  • a data type such as "integer" or "email"
  • a single XPath constraint
If any of these validations failed, the user would get either a custom alert message for the control, or a generic Form Runner alert message.

With Orbeon Forms 4.3, this is still available but is improved in the following ways:
  • You can now set multiple XPath constraints, each with its own alert message.
  • You can, in addition to errors, create warnings and informational messages.
The user interface of Form Builder has been updated to reflect this. We used to have two separate dialogs to modify information associated with a control: a "details" dialog and a "validation" dialog. We haven't been happy about this for a long time as the distinction appeared arbitrary. So they are now unified and functionality is separated by tabs:
  • Basic Settings
  • Validations and Alerts
  • Formulas
  • Help Message
The tab relevant to validation is called, well, "Validation and Alerts":

This might look scary at first, but in fact things are pretty simple: each line represents a separate validation. The first two validations (whether the control is required and the data type) are fixed. All the other validations are optional and are constraints validations.

Each constraint validation has the constraint itself, expressed in XPath, a level, and an alert message.

There are three main use cases for adding multiple constraints:
  • For readability, so that individual constraints are simpler.
  • In order to provide a separate alert message for each constraint.
  • In order to specify other constraint levels.
The notion of constraint level is new in 4.3. Up to now, any failed validation was was an error. Now you can add constraints that just warn the user, or display an informational message. Here is an example of warnings and informational messages appearing in a simple form:

As was the case before, messages appear as needed right under the controls, as well as in the error summary at the bottom of the page. In addition, the form title in the browser and badges in the navigation bar indicate the validation status of the form.

The difference between the error level and the warning and info levels is that the latter do not prevent form data from being submitted. Instead, if there are warnings or informational messages, then a confirmation dialog shown the user before submitting the data:

The submission process, by the way, is fully configurable via the processes mechanism (see the blog post and doc).

This post just covers the basics! For the reference documentation, see Form Builder ~ Validation. We hope you like this feature!