Strategies for Validating CSLA Objects and Triggering Save in Blazor #4432
Unanswered
ecaldentey
asked this question in
Questions
Replies: 1 comment
-
By default, rules don't run in the data portal create or createchild operation methods. This is for performance reasons. In your case (and in many cases) it is desirable to run rules in those operations, because otherwise things like Just call |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have a CSLA class called BusinessDeal whose graph is complex because it has many child classes such as BusinessDealAnnex and, in turn, BusinessDealAnnexClient. In a Blazor page, I manage the class, and to manage the list of children (BusinessDealAnnex) and grandchildren (BusinessDealAnnexClient), I use components on the main page. On the main page, I have buttons that allow saving changes made to the BusinessDeal object and its children to the database.
But I want to enable the Save button when at least the required fields for the root object and its children have information. Although the required properties are defined with their attributes indicating that they are required and the minimum lengths for string properties, the class remains valid even when those fields have not been filled.
Here is an example of the definition of some properties:
[Display(Name = "BIZDEAL_ID")]
[Required(ErrorMessage = "The BizdealId field is required")]
public static readonly PropertyInfo BizdealIdProperty = RegisterProperty(nameof(BizdealId));
public Decimal BizdealId
{
get => GetProperty(BizdealIdProperty);
set => SetProperty(BizdealIdProperty, value);
}
[Display(Name = "BIZDEAL_TYPE")]
[Required(ErrorMessage = "The BizdealType field is required")]
public static readonly PropertyInfo BizdealTypeProperty = RegisterProperty(nameof(BizdealType));
public Int16 BizdealType
{
get => GetProperty(BizdealTypeProperty);
set => SetProperty(BizdealTypeProperty, value);
}
[Display(Name = "BIZDEAL_CODE")]
[Required(ErrorMessage = "The BizdealCode field is required")]
[StringLength(30, ErrorMessage = "The BIZDEAL_CODE field cannot exceed 30 characters")]
public static readonly PropertyInfo BizdealCodeProperty = RegisterProperty(nameof(BizdealCode));
public String BizdealCode
{
get => GetProperty(BizdealCodeProperty);
set => SetProperty(BizdealCodeProperty, value);
}
I need to do something additional for CSLA to detect that the conditions of the properties are not met and mark the object as invalid if the attributes are not satisfied.
What is the best way in the graphical interface to validate that the object is complete in order to enable the save button?
Any help will be appreciated.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions