Replies: 6 comments
-
I'm away at the moment but I'll have a look at this when I'm back at my desk in a couple of weeks time. |
Beta Was this translation helpful? Give feedback.
-
There are several threads of conversation on this topic in several different places. I'd like to collect all the requirements for a validation module into one place - which might as well be here. To start, the module should:
Those two requirements mean we need to be create a Validator class where instances of that class can validate any object. (I have some ideas on how to do that cleanly). |
Beta Was this translation helpful? Give feedback.
-
What ORM are you talking about? |
Beta Was this translation helpful? Give feedback.
-
We'd like any validator we add to work with apps using https://github.com/anvilistas/anvil-orm as well as apps that do not. We started that discussion in #48. (I can't easily look at your module whilst I'm away. I only have a phone to hand). |
Beta Was this translation helpful? Give feedback.
-
I understand, I didn't know there was an ORM library. You say "I have some ideas on how to do that cleanly", so let's talk about it when you are back and you can talk about it. You say "work with the ORM library such that ORM model instances can be validated". In the database I usually have a few columns used for searching and sorting and a few simple object containing the bulk of the data. In the UI I have some forms used to search and filter and other forms used to edit data. In the search forms I use the validation, but I don't have any interaction with the database yet. I might have a SearchFilter object in complex cases, but that object wouldn't be an ORM object. In the data editing forms I expose data mostly buried inside the simple object columns, so I would not be able to set the validation for the fields in the ORM. So, without having any idea about your idea for integrating ORM and Validator, I think that the Validator will be used much more than the ORM and should be kept as simple a possible. Perhaps the Validator should be kept as is and the ORM should have something like |
Beta Was this translation helpful? Give feedback.
-
I envisage something like a Validator class that takes any object as its 'subject'. It also has the means to define 'validation rules' which it can then run against the subject to determine its validity. The subject can thus be any object at all - an ORM model object, a Form instance or anything else. The idea is that the validation module would be entirely standalone and not coupled to anything else - not the ORM and not the anvil modules either. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been using a validator module for some time in my apps.
Recently I added anvil-extras as a dependency and replaced Notifications with popovers. Then I added the validator module to my local copy of anvil-extras, and I think it belongs in there.
Here is a little demo: https://anvil-extra-validator-demo.anvil.app
Here is the clone: https://anvil.works/build#clone:TCCWPPUBDJMPIWX4=2VPJ7MKCXM5QACBJPYL3K3M5|5BZXIVR2H2F2P4BE=WSQ45K5PC34C74ZJN6UXXEYJ
If you think it can be a good addition to anvil-extras, I will format and clean it up following the guidelines, add a page to the documentation and submit a pull request.
Beta Was this translation helpful? Give feedback.
All reactions