When use CustomField and ToUpperCase rule of cslacontrib, the BO's state IsDirty is incorrect.

When use CustomField and ToUpperCase rule of cslacontrib, the BO's state IsDirty is incorrect.

Old forum URL: forums.lhotka.net/forums/t/11277.aspx


simon posted on Tuesday, April 03, 2012

When the TextBox(binding MaterialNo and apply ToUpperCase rule) changed. the ViewModelBase's CanSave is still false.

If remove the below code in BussinessCore of CustomFiled, will run well.

 

     public override bool IsSelfDirty

        {

            get

            {

                if (IsDeleted) return true;

 

                var isSelfDirty = false;

                foreach (var registeredProperty in this.FieldManager.GetRegisteredProperties())

                {

                    if (registeredProperty.RelationshipType.HasFlag(RelationshipTypes.Child))

                    {

                        // skip lazy fields (is by definition child object)

                        if (!registeredProperty.RelationshipType.HasFlag(RelationshipTypes.LazyLoad))

                        {

                            var fieldData = FieldManager.GetFieldData(registeredProperty);

                            // fielddata object implements ITrackStatus it is a child object and must be excluded

 

                            if (!(fieldData is Csla.Core.ITrackStatus))

                            {

                                if (this.FieldManager.IsFieldDirty(registeredProperty))

                                {

                                    isSelfDirty = true;

                                    break;

                                }

                            }

                        }

                    }

                    else

                    {

                        if (this.FieldManager.IsFieldDirty(registeredProperty))

                        {

                            isSelfDirty = true;

                            break;

                        }

                    }

 

                }

                return isSelfDirty;

            }

        }

JonnyBee replied on Tuesday, April 03, 2012

1. That is the expected behvior when datasource updatemode is OnPropertyChanged. If you want to change the characters to uppercase as the user types then this must be handled in the UI code. 

2.  CustomFieldData ha its own implementation of IsDirty handling. You'll have to debug this code.

simon replied on Wednesday, April 04, 2012

I found the reason.

the ToUpperCase will invoke the MarkClean  again.

public override void MarkClean()

{

base.MarkClean();

this.SetOriginalValue(this.Value);

}

this cause the OriginalValue be set again with the new value( convert by ToUpperCase).

but i don't find solution to avoid it.

Please help me. thank you.

JonnyBee replied on Wednesday, April 04, 2012

Hi, 

In this case look for overrides of LoadProperty in your business objects (BusinessCore?).

CSLA rule engine will only call LoadProperty to update the value.

Copyright (c) Marimer LLC