Validator in advanced GridVIewColumns

I use Validator + InvalidCssClass a lot in my forms. I also like Auto UI and other stuff that generates forms and tables based on model for me. However I am struggling to put these two concepts together.


public class Model
    public string Name { get; set; }

    public string Description { get; set; }
        <bp:GridView DataSource="{value: Models}"
            <bp:GridViewTextColumn HeaderText="Rok" Value="{value: Year}" Validator.Value="{value: Year}"/>
            <bp:GridViewTextColumn HeaderText="Popis" Value="{value: Description}" />

Validator.Value has no effect here. I have to convert bp:GridViewTextColumn to bp:GridViewTemplateColumn and define templates for Insert and Edit with Validator in it. This results in a lot of code. Or is there easier way that I am missing?

How to achieve applying Validator.Value in generated fields?

Off: My ultimate goal is to use only <auto:AutoBpGridViewColumns />. I accomplished something similar in forms using custom [SelfValidator] attribute, but grid views are more complicated and I would like to consult my direction here first.

I think that you can specify BusinessPack.AllowAutoValidationProperty on the GridView, then Validator.Value will be set automatically to whatever is in Value. I don’t know if it can be set explicitly without declaring the templates.

1 Like

This is awesome. It solves all my validation problems and now I can get rid of my custom code that was doing something similar and refactor a lot of code.

There is one problem about this property: I was not aware of it. It should definitely be mentioned in docs. I assume you don’t want to mix basic concept documentation with commercial BP information. I f it is not the case, let me know and I will write something.

Many thanks @exyi

Thanks for the note, I never know what is in the docs and what isn’t. I have added a mention to GridView inline editing (where it’s essentially required as well as some basic validation docs (Mention BusinessPack.AllowAutoValidation property by exyi · Pull Request #232 · riganti/dotvvm-docs · GitHub).

Well usually, it’s not a concern, since the basics are not really affected by BP or other additional packages. I guess it’s fine, as long as it’s crystal clear what is BP or built-in and as long as the docs don’t look like a pay-to-win game :grin:.