How can we improve Breeze.js?

Breeze + Knockout validation -> new features

If App uses breeze and ko validation, I suggest to

add knockout validation rules for every fetched entity as showed in code example (here coffee code implementation for dataPropeties):

addRules = (breezeEntity) ->
return if breezeEntity.koValidationRulesAdded
entityType = breezeEntity.entityType
for property in entityType.dataProperties
continue unless property.validators.length > 0
do (property) ->
displayName = property.displayName or property.custom?.displayName or property.name
breezeEntity[property.name].extend
validation:
validator: (value) ->
if breezeEntity.entityAspect.validateProperty property.name, {displayName: displayName, entity: breezeEntity}
@message = ""
return true
else
@message = breezeEntity.entityAspect.getValidationErrors(property.name)[0].errorMessage
return false
message: ""
return
breezeEntity.koValidationRulesAdded = true
return

this code allows:
1) to validate single property with usage of all entity properties and triggers property validation on changes in any properties that validation depends on. For example I can extend entity with fields like password and passwordConfirmation and add custom breeze validator for passwordConfirmation that checks equality of fields.
2) to show validation messages separately for each property in html form using ko binding.

5 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Anna shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base