[Bese-devel] validators and null values

Nathan Bird nathan at acceleration.net
Fri Apr 28 02:43:09 UTC 2006


>Most of the validators are already setup to return T, indicating valid,
>when
>given a nil value. The idea being that if you want to require a value then
>use a not-empty-validator as well.
>
>Introduce a "value-validator" subclass of validator that becomes the
>superclass of most of the current validators. The :around validate for this
>does the appropriate null check, and only applies the validator if there is
>a value to test.  [...]
>Really the only validator I don't think would fall under this right now is
>the not-empty-validator.

I changed my mind on string=-validator. That should be called regardless of
whether the field it is on has a value. If the other-field has a value and
this one doesn't then we want to indicate an error.

The external interface should be largely unchanged, with a few semantic
differences of validators succeeding where previously they failed.
Specifically: if you want a field to be required, the way to do it is a
not-empty-validator.

Other issues I came across while implementing this scheme:

Number-range-validator should inherit from is-a-number validator, it doesn't
make sense to check if a string is inside a number range, and so we've got
to do the work of ensuring it is a number first anyways. Previously this was
being handled kindof by parse-integer (would return nil or any integer found
in the string), and would break for number range validator (I expanded the
examples/forms.lisp in order to show this)

Is-an-integer-validator previously allowed 11.3 without giving any error and
returned value 11. It now fails the is-an-integer validate.


Things I came across but didn't change:

(value number-field): if the client didn't enter anything in, shouldn't we
return nil and not 0?

I don't think there is a need for the integer-range-validator anymore.
Number-range-validator takes care of it, and if you are using the
integer-field you already have the is-an-integer-validator attached.

Adding a 'required' initarg (that is itself optional :-) to form-field to
automatically attach the required validator to anything. This is such a
common case we probably want to make it easier.

The javascript validation is still untested, but was broken previously do to
an id mismatch (at least on the examples page). I will try to look into this
further somewhere in the near future.


Buy now (from ucw_public) and you ALSO GET!
* a second patch where I rearrange the file a bit to try to reduce the
number of style-warnings due to undeclared functions.
* more documentation
* Russ' regex validator, an improved email validator, and a phone-number
validator based upon it.


Nathan Bird





More information about the bese-devel mailing list