Hi all, Hi Antonio,

In the 2.1.2 version of Cocoon, a call to form.getWidget().isValid() always returns false, even if the form seems to be valid...
Is it the right behaviour ?


For me, this call would be far more practical than testing the null value of all required widgets... or do I miss something ?

function myValidator(form) {
    if (!form.getWidget().isValid())
        return false;

    ...my business code...
}

Furthermore, according to woody.js :
<code>
        var finished = this.form.process(formContext);
        var evt = formContext.getActionEvent();
        if (evt != null) {
            this.submitId = String(evt.getActionCommand());
        } else {
            this.submitId = undefined;
        }
        // If either validation was successfull or there was an event, call the 
validator
        if ((finished ||this.submitId != null) && this.validator != undefined) {
            finished = this.validator(this);
        }
        if (finished) {
            break;
        }
</code>

The validator seems to call the flow validator _only if_ the form processed correctly (ie is valid) (cf Form.java). But is it really the case ? It appears that we need to test null values of required fields in the validator, and that isValid() returns false in the flow validator...

--
Olivier


On 07/01/2004 23:55, Antonio Gallardo wrote:
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