Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    validate on blur?

    Hi again, I have the following code

    Code:
    isc.DynamicForm.create({
        ID: "exampleForm",
        fields: [{
          .....
          changeOnKeypress: true,
          validators : [{
            type : "custom",
            condition : function (form, item, value) {
              ....
            }
          }],
          blur : function () { XXXX }
        },{
          .....
          changeOnKeypress: true,
          validators : [{
            type : "custom",
            condition : function (form, item, value) {
              ....
            }
          }],
          blur : function () { XXXX }
        }]
    });
    and I want to validate each item INDIVIDUALLY when on blur, but I don't know how.

    I don't want to use "validateOnChange" since I have the "changeOnKeypress: true" and I can not remove it (to solve another problem of other thread). With "changeOnKeypress: true" set while typing maybe the value doesn't fit the validation pattern since it is not yet completed and un-desired error message appears. (This is why I need it just on blur)

    I don't want to use "exampleForm.validate()" since it validates the entire form and I want just validate the item which I blur

    Does it exist something like "this.validate()" (this obviously doesn't work) that I can replace by the XXXX (of the above code) to validate?

    Thanks!

    #2
    would this work in your blur() handler:

    blur: function() {
    var status = this.validators[0].condition(item, form, item.getValue());
    if (status === false)
    {
    form.setFieldErrors(item.name, 'error message', true);
    }
    }

    Comment


      #3
      Suggestion did not work

      Hey I tried the above suggestion and got that this.validators[0].condition is not a function.

      Any suggestions.

      Comment


        #4
        It worked for me

        mackram do you have "validators" defined in your form item?

        also notice that a proper representation of the solution for this particular case would be

        Code:
        blur: function() {
          var status = this.validators[0].condition(this, this.form, this.getValue());
          if (status === false) {
            this.form.setFieldErrors(this.name, 'error message', true);
          } else {
            this.form.clearFieldErrors(this.name, true);
          }
        }

        Comment

        Working...
        X