Validation not firing when pressing submit button on nested numeric property #62039
Closed
1 task done
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
Is there an existing issue for this?
Describe the bug
Dear friends, I would like to report what I consider a bug in the blazor model validation when using InputNumber in a nested object.
Consider the following simple object composed of 2 classes as follow:
public class ObjectInv
{
public string id { get; set; }
[Required(ErrorMessage ="Product Name is mandatory!", AllowEmptyStrings =false)]
public string name { get; set; }
public Data? data { get; set; } = null;
}
and the property of type " Data" is defined as follows:
public class Data
{
.... MORE PROPS....
}
The expected behavior is that when I press the submit button in the form, it fires the validation as shown in the following picture:
Unfortunately when I press the submit button (in this case, the " add me!" button) only the property in the main object (Product Name) is validated, the other one, is completely ignored, as shown below:
The validation message is shown only if I manually input for example a negative number or remove a number and/or use the up/down number selector on the right of the control... but as soon as I press the submit button, it voids the error message and says all is good, as shown below
and when I press the button, the Product Price says to be ok... even knowing that before it was saying it was not...
I tried to use DataAnnotationsValidator and the ObjectGraphDataAnnotationsValidator but the behavior is the same, tried also v7 server side, not 8, but the behavior is there too.
I created another property, a copy of the actual price property from the Data object, and put it in the root of the main object, and there it behaves correctly, in the following example, you will see 2 prices, the first one is the problematic, and the other one is a property called price2, in the root
Expected Behavior
The expected behavior is that the validation should fire correctly for numeric properties in the root object and should also work inside a nested property (in this case, Data > price ) when we press the submit button in the form as shown in the following image:
Steps To Reproduce
Please download the project files, run the project and try to validate PRODUCT PRICE (price) located in the Data object of the root object.
BlazorSampleApp1.zip
Exceptions (if any)
No response
.NET Version
8 and 7
Anything else?
No response
The text was updated successfully, but these errors were encountered: