Ticket Q440548
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Filtering - Create a built-in criteria function to check if an XPO object is new or saved

Vaildation only if IsNewObject=true?

created 12 years ago

I have a object (Contract) that is editable on creation, but then after it is saved, I make all fields not editable by following the example provided in
http://www.devexpress.com/Support/Center/Question/Details/Q310354

Now my problem is that I have a single STATUS field that needs updating as the 'Contract' goes through various phases in the business, but I have validation rules on dates. Now as time progresses certain validations fail on the dates and this then prevents me from updating the STATUS of the contract.

My question is: Is there a way to make validation rules ONLY apply when IsNewObject=true and otherwise not to be applied.
I have hunted high and low and the only solution I can come up with is implementing CustomValidation.

Any guidance appreciated.

Answers

created 12 years ago (modified 12 years ago)

Hello Ralf,
It is possible to accomplish this task via the rule's TargetCriteria parameter. Here is an example:

C#
private string _RequiredField; [RuleRequiredField("asd", DefaultContexts.Save, TargetCriteria = "IsNewObject")] public string RequiredField { get { return _RequiredField; } set { SetPropertyValue("RequiredField", ref _RequiredField, value); } } [Browsable(false)] public bool IsNewObject { get { return Session.IsNewObject(this); } }

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.