jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

custom property with RequiredIf #126

Closed JasonLounsbery closed 8 years ago

JasonLounsbery commented 8 years ago

I have a property that determines if a field is required. It always says it is required

    [DataMember]
     [Description("Address Line 1")]
    [RequiredIf("isRequired(ADDRESS,'STREET') == true", ErrorMessage="Address is Required")]
    public string ADDRESS { get; set; }

[DataMember] [Description("Address Line 2")] [RequiredIf("isRequired(ADDRESS2,'STREET2') ", ErrorMessage = "Address is Required")] public string ADDRESS2 { get; set; }

public bool isRequired(string value,string FieldName) { return false;

    }

I removed the code for IsRequired so it always returns false

ADDRESS and ADDRESS2 are always required. Can something like this be done?

jwaliszko commented 8 years ago

I'm afraid I cannot help you because your question doesn't define what the problem is.

JasonLounsbery commented 8 years ago

The issue is that the properties are being flagged as required regardless of what IsRequired is returning. I thought that the RequiredIf attribute would reflect what ever the function IsRequired returned. If IsRequred returns True and the Address field is blank, the error message shows up. if IsRequred returns False, and the Address field is blank, the error message shows up.

JasonLounsbery commented 8 years ago

The issue is that the properties are being flagged as required regardless of what IsRequired is returning. I thought that the RequiredIf attribute would reflect what ever the function IsRequired returned. If IsRequred returns True and the Address2 field is blank, the error message shows up. if IsRequred returns False, and the Address2 field is blank, the error message shows up.

Here is my code. For testing I have isRequired returning false.

…Model

[DataMember] [Description("Address Line 2")] [RequiredIf("isRequired(ADDRESS2,'STREET2') ", ErrorMessage = "Address is Required")] public string ADDRESS2 { get; set; }

public bool isRequired(string value,string FieldName) { return false; }

Jason Lounsbery GEMMS 10201 N. Illinois Street Suite 140 Indianapolis, IN 46290 www.gemmsnet.com Ph: 317-819-5060 Ph: 800-773-3111 Fax: 317-819-5071


The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in relation to the contents of this information is strictly prohibited and may be unlawful. Neither the sender nor the represented institution are liable for the correct and complete transmission of the contents of an e-mail, or for its timely receipt.

From: Jarosław Waliszko [mailto:notifications@github.com] Sent: Saturday, June 25, 2016 3:48 PM To: jwaliszko/ExpressiveAnnotations ExpressiveAnnotations@noreply.github.com Cc: Jason Lounsbery jlounsbery@gemmsnet.com; Author author@noreply.github.com Subject: Re: [jwaliszko/ExpressiveAnnotations] custom property with RequiredIf (#126)

I'm afraid I cannot help you because your question doesn't define what the problem is.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/jwaliszko/ExpressiveAnnotations/issues/126#issuecomment-228567269, or mute the threadhttps://github.com/notifications/unsubscribe/ATDQc7rxxCVAfDDSTaoudUcdCk-08Vf3ks5qPYXYgaJpZM4I3ahn.

jwaliszko commented 8 years ago

You should probably take a look at the documentation related to defining your own methods - if you are using client-side validation you need to define respective method at client-side as well. I assume you have an error related to undefined reference - check your web console output.

Also, I advise you to use GitHub directly instead of emails when posting here, because you have the opportunity to format your messages using markdown.