Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect basic validators in app (translated from wq.db models) #76

Open
tomaszn opened this issue Dec 3, 2016 · 3 comments
Open

respect basic validators in app (translated from wq.db models) #76

tomaszn opened this issue Dec 3, 2016 · 3 comments

Comments

@tomaszn
Copy link
Contributor

tomaszn commented Dec 3, 2016

If a Django model field is defined with validators, they should be propagated down through the configuration and used for new/edit screens on the client.
In general it is impossible to use the same validation code on the client (Python code run on the server vs JavaScript in the browser). However:

  • basic validators could be translated (MaxValueValidator, MinValueValidator, MaxLengthValidator, MinLengthValidator, DecimalValidator);

  • stubs for the rest could be generated and a warning issued; if a validator is used by different models, it should also be reused on the client side.

@sheppard
Copy link
Member

sheppard commented Dec 7, 2016

Yes, it would be good to automate more of these. Most of the basic validators could likely be translated directly into HTML5 attributes on the <input>. We would just need to think a little about how to represent these in the JSON config - and also whether we can map this to the output of xlsconv. Ideally implementers could start with an XLSForm containing constraints, and have the templates and Django models both generated with the appropriate validators already in place. The one challenge might be that the XLSForm constraint syntax is written more like a query language so it might not have a one-to-one mapping to Django's concepts.

For more complex validators I do like the idea of implementing stubs. My one question would be if you strictly need instant offline validation, or if you are okay waiting for a sync. wq.app and the default templates are set up so that if the server validation fails, you can re-open the failed record from the outbox to see the server's error message(s) for each field and for the record as a whole.

@tomaszn
Copy link
Contributor Author

tomaszn commented Dec 18, 2016

Instant offline validation would be useful, because after returning from the field one may not remember the proper answer. Example: a required field "tail length" was left empty, when it is essential for scientists.

@sheppard sheppard added this to the 1.0 milestone Jan 5, 2017
@sheppard sheppard modified the milestones: 1.0, 1.1 Jun 20, 2017
@sheppard sheppard modified the milestones: 1.1, 1.2 Apr 23, 2018
@sheppard
Copy link
Member

I would still like to do this, though I think I would like to transition toward a standard schema object (wq/wq#40). Moving to the 2.0 milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants