Form Validation for child components

Posted 98 days ago by cwinemanRID
0

Hello,

I'm having trouble getting validation working in a child component in a form. Here's a fiddle with the two relevant razor files: https://blazorfiddle.com/s/4nujac13

I couldn't get it working there, but it's pretty simple.  

Screenshot:

https://ibb.co/KhKJ2jW

At first, I couldn't get AddressComponent to show any visual cues that a field was required for any of the properties. But then I learned about ObjectGraphDataAnnotationsValidator and I was able to get message for the SimpleModel.SimpleAddress.City to show as required. It works exactly like I wanted for complex types.  

However, I was surprised to see that I couldn't get the required validation showing for the SimpleModel.SimpleString property. On the submit button click, not only does it not show that it's required on the input, but it seems to be over-writing the value with the blank value from the parent (or with whatever initial value was set in the parent).

Can anyone help me understand what I'm doing wrong?

Thanks,

-Corey

  • 0

    Maybe try making the SimpleString property not nullable and see if the validation works as expected?

    Posted 65 days ago by selliott
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 0
An error has occurred. This application may no longer respond until reloaded. Reload 🗙