Sylvain Wallez dijo:
> Hi all,
>
> I encountered a problem today: I have a form where a field is required
> or not depending on the value of another field. I wanted to control this
> using the validation (with a <wd:assert>) but couldn't as the validators
> aren't called if the value is null.

True, but you can "attach" your own validator in javascript. We are doing
this and work fine. Example:

function createform(form) {
  form.validator = ValidateCreatePlan;
  form.showForm("create-form-display");
  cocoon.sendPage("success");
}

function ValidarCrearPlan(form) {
  var result = true;
  if (form.getWidget("recall").booleanValue() != null) {
    if (form.getWidget("number of recalls").value() == null) {
      addMessage("Please add the number of recalls");
      resultado = false;
    }
  }
  return result;
}

> To allow this, I wanted to propose that, when a field isn't explicitely
> marked as required, validators be called even if the value is null.

No a good idea. This was througly discussed before. In fact that was the
"old" approach and after a long discussion, we settled to let it as is
now:

http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106148623116701&w=2
(please follow the thread).

> But then comes another problem, since most validators expect a non-null
> value and will break on NPE if no value is given.
>
> So what about the following changes:
> - when a field isn't marked as required, validators are called even if
> the value is null,
> - validators that need a value to do their job (e.g. regexp, range,
> email, etc) will return "true" (valid) for a null value

Hmm. We are breaking conventions.

> - other validators (such as assert) will behave according to their
> semantics with null values.

Reply via email to