7 Replies Latest reply on Oct 9, 2014 1:06 PM by MatLac

    Validation:  remove my field from an array

    MatLac Level 1

      Four text fields "field1", "field2", "field3", "field4"

       

      I have a custom validate script that compare its value to the values of the other fields.  An array containing all four fields is used in the process.  I want to remove the field that is validated from the array so it is not compared to "itself" (or its former value should I say).

       

      var aMIP = [this.getField("OPE003.EVEN.1.MIP"), this.getField("OPE003.EVEN.2.MIP"), this.getField("OPE003.EVEN.3.MIP"), this.getField("OPE003.EVEN.4.MIP")];

      //removing same & emtpy values from aMIP

        for (var i = aMIP.length-1; i >= 0; i--) {

         if ((aMIP[i].value == "")||(aMIP[i].value == event.value)) aMIP.splice(i,1);

        }

      console.println(aMIP.length);

       

      I discovered that if I fill only the first field, aMIP.length = 0

      If I change the value of the same field, aMIP.length = 1

       

      Does it have to do with the fact that during validation, event.value doesn't refer to the value of the field but rather the value that is yet to be commited by the validation process?  So basically, aMIP[i].value != event.value even if it is the same field.

       

      Also aMIP.indexOf(event) , aMIP.indexOf(event.target) & aMIP.indexOf(event.source) all return -1.

      What condition should I use to remove my field from the array?