0

I am using Breeze.js data-z-validate attribute in order to get "out of the box" validation messages to display in my angular app.

The Breeze metadata is coming from EF - an example model property looks like this:

 [MaxLength(100),Required,Display(Name = "My Custom Field Name")]
 public string Name { get; set; }

The Breeze validation message always comes back with the real name of the property, not the displayname. For eg. "name is required".

I want the breeze validation message to be displayed using the display name attribute so it will be:

"My Custom Field Name is required".

I have also tried using the DisplayName attribute:
[DisplayName("My Custom Attribute")]

but I get the same behaviour regardless.

Am I missing something or does z-validate not allow for the display/displayname attribute? What is the best / recommended way to get a 'friendly' validation message back?

Pacificoder
  • 1,581
  • 4
  • 18
  • 32
  • 1
    possible duplicate of [how to add extend breeze entity types with metadata pulled from property attributes](http://stackoverflow.com/questions/26570638/how-to-add-extend-breeze-entity-types-with-metadata-pulled-from-property-attribu) – Jeremy Danyow Dec 28 '14 at 12:22
  • Haven't been able to get this all to work yet but I believe Jeremy's comment is the right way to go - thanks – Pacificoder Dec 30 '14 at 17:37
  • Let us know when you have something that feels good. ZValidate is a proof of concept anyway. Feel free to improve it or publish an alternative. We'll gladly point to it in our docs. – Ward Dec 31 '14 at 17:13

1 Answers1

0

I've used a solution that isn't ideal, but works. The downside is that the friendly name isn't part of the entity, it's in a separate table. The extra maintenance may not be worth it for some but it is in my case. The first thing is to create a table that has the name of the entity, the property, and the friendly name. At startup, I retrieve the rows from that table and loop through it, updating the entity displayName in breeze. To update the display name for the "name" property of a "contact" entity for example: var eType = manager.metadataStore.getEntityType("contact"); var dp = eType.getProperty("name"); dp.displayName = "My Custom Field Name"; Ideally it should be part of the entity definition but I don't know if the current version supports it.

mwill
  • 424
  • 7
  • 21