Can breezejs check a newly created object for changing the NOT property to SAVE

from the breezejs manual: "Breeze automatically checks entities in the cache. This is usually not done for individual objects. For example, a newly created Client is technically invalid because its community_name is null and this property is required. Breeze does not confirm the client until you add it to the cache "This gives you time to set the values โ€‹โ€‹of the new object before it enters the cache and activates the scan."

My question is in the above context:

Samples floating on the network about breezejs and validation always show a check when a new object will be created and the SAVE button is pressed.

Can breezejs also check for property changes when I enter from one input field, enter 100 characters (10 are allowed) and a tab in the next input field? I just want to show my validation error message every time I change NOT properties when the user clicks the Save Changes button.

Or does this not work for the newly created object, since it has not yet been added to the cache? Does this work only for entited editing?

+4
source share
2 answers

By default, the object is added to the cache. When you create an object, you can explicitly set its entityState to Detached or any other state if you want. ( entityManager.createEntity('entityType', null, breeze.EntityState.Detached) )

As for validation, you can manually verify entities in any state at any time. If you want to validate when a property changes, just subscribe to the entityAspect.propertyChanged event. The propertyChanged event will give you access to the entity itself, the name of the changed property, the old value and the new value. Then you just need to check the validation of properties using entity.entityAspect.validateProperty(propertyname) and process the results.

Sign up for property changes and manually confirm
(The code below is combined with breeze examples)

 // assume order is an order entity attached to an EntityManager. order.entityAspect.propertyChanged.subscribe( function (propertyChangedArgs) { // this code will be executed anytime a property value changes on the 'order' entity. var entity = propertyChangedArgs.entity; // Note: entity === order var propertyNameChanged = propertyChangedArgs.propertyName; var oldValue = propertyChangedArgs.oldValue; var newValue = propertyChangedArgs.newValue; if (!entity.entityAspect.validateProperty(propertyNameChanged)){ //Property is not valid. Inform the user if needed. } }); 

For more help and examples, see these links:
Subscribe to propertyChanged event
Manual property check
Create a new object

+4
source

I think it is possible, you can do a manual check.

 if (!newCustomer.entityAspect.validateEntity()) {/* do something about errors */} You can also validate a specific property: if (!newCustomer.entityAspect.validateProperty("CompanyName")) { /* do something about errors */} 

I have the following examples: http://www.breezejs.com/documentation/validation

Hope this helps you.

+1
source

All Articles