wq / wq.app

💻📱 wq's app library: a JavaScript framework powering offline-first web & native apps for geospatial data collection, mobile surveys, and citizen science. Powered by Redux, React, Material UI and Maplibre GL.
https://wq.io/wq.app/
MIT License
120 stars 32 forks source link

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

Open tomaszn opened 7 years ago

tomaszn commented 7 years ago

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:

sheppard commented 7 years ago

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 commented 7 years ago

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 commented 5 years ago

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.