0

I am trying to do the validation for the data properties present in complex type array. Below shown is the sample breeze schema and the complex type used.

Breeze schema:

    {
        "name": "mailingAddress",
        "complexTypeName": "Address:#test",
        "isScalar":false
    }

Complex type: (Address.json)

    {
        "name": "address",
        "dataType": "String",
        "validators": [
            {
                //some custom validator
            }
        ]
    }

In this case ,the sample data object will be like as shown below

{
mailingAddress:[
      {
        address:"123 street"
      },
      {
        address:"Main Street"
      }
  ]

}

If I change the address, the validator associated to the address data property will trigger.

My question is: I am changing the address of the first object (mailingAddress[0]), how does breeze knows that I have changed the first address object? Is there any way to take the changed array index?

I had checked the propertyName present in context, but it does not have the exact path.

  • Expectation : mailingAddress[0].address
  • Actual : mailingAddress.address

I am not able to do the custom validation properly because of the above problem. Kindly provide a solution for this issue.

Thanks, Dinesh

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dinesh Kumar
  • 107
  • 1
  • 10
  • Excellent question. I tripped over this ... and thought I found the answer. I've forgotten already. We should document it. Expect more information soon. – Ward Mar 11 '15 at 20:51
  • @Ward - Thanks , waiting for your valuable information. – Dinesh Kumar Mar 12 '15 at 18:56
  • Waiting for the right person to return from vacation. I hope we'll see an answer soon. – Ward Mar 16 '15 at 08:56
  • One more interesting thing to note: **** "index is available directly under the context object if we do the validation for the entire entity, but during the validation on a propertyChange the index is not available" ****I am currently using breeze v1.5.1 . Refer below lines present in breeze.debug.js ****Line no:3964 (validateTarget())- **array index is set to the context.index, this code will execute during the validation of entire entity.**. ******Line no:5402 (updateStateAndValidate()) - **array index is not set in the context,this code will execute during the validation on propertyChange** – Dinesh Kumar Mar 17 '15 at 13:42
  • Added the code snippet for reference:(breeze.debug.js v1.5.1). 1)Line no:3964-**This is code snippet for validation of entire entity** `var context ={entity: entityAspect.entity}; if (coIndex !==undefined) { context.index = coIndex; }` 2).Line no:5400- **This is the code snippet for validation on propertyChange**. `if (entityManager.validationOptions.validateOnPropertyChange) { entityAspect._validateProperty(context.newValue, { entity: entityAspect.entity,index:context.index, property: property, propertyName: context.propertyName, oldValue: context.oldValue }); }` – Dinesh Kumar Mar 17 '15 at 14:03
  • I'm tripping over this as well... @Ward Has this person come back from vacation yet? ;) – Heretic Monkey Dec 09 '15 at 22:25

0 Answers0