Search code examples
validationbooleanbreezeclient-siderequired

Why is breeze "required" property validation rule not firing when validating new entity?


I'm attempting to use the [Required] functionality for Breeze's Client-Side validation. I can do so but the only success i have had thus far is with strings. I'm attempting to do the same with a boolean but Breeze will not recognize any entity validation.

Here is my domain code snippet:

     [Table("Uwrl")]
public partial class Uwrl
{
    public Uwrl()
    {
    }

    [Key]
    public int customerNumber { get; set; }

    [Required]
    [StringLength(40)]
    public string customerName { get; set; }

     [Required]
    [StringLength(50)]
    public string customerStatus {get;set;}


  public int? taxId {get;set;}

     [Required]
  public bool coAdministration{get;set;}

Here is my controller code snippet to test for validation errors:

            var testEntity = UWRLService.createEntity(entityName, uwrl.customerData);
          if (!testEntity.entityAspect.validateEntity()) { alert("Didn't VALIDATE!"); }

Here is my view to ensure my particular property has z-validate in it:

                    <td style="text-align:right">
                    Co-Administration:<select ng-model="uwrl.coAdministration" data-z-required>
                        <option></option>
                        <option value="True">Yes</option>
                        <option value="False">No</option>
                    </select>
                </td>

Both customerName and customerStatus works. The customerStatus is even a select (drop-down)--exactly like the coAdministration property. How does one validate booleans? Validating strings works perfectly for me...what's the difference?


Solution

  • The boolean property is not nullable which means it's initial value will be "false".

    "false" is not null or empty so the required validation rule is not firing.