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

Forcing integer widget to require non-zero value before saving form #455

Open
she-weeds opened this issue Jan 13, 2020 · 0 comments
Open

Comments

@she-weeds
Copy link

she-weeds commented Jan 13, 2020

Is it possible to force certain numeric widgets to still be 'Required' if the value is 0 (or the minimum value)? I have a fair number of required numeric fields for non-zero measurements, but because they default to 0 (or the minimum value) it gets interpreted as filled-in, which results in assessors skipping over that field by mistake and a heap of erroneous data.

I've got a clumsy workaround by adding the following code to accept() in form.py:

numfieldlist = ['basal_d_cm','height_m','width_m']
numwidgetlist = [self.boundwidgets[field] for field in numfieldlist]
zerovallist = [w.unformatted_label for w in numwidgetlist if w.value() == 0]
if zerovallist:
    raise utils.MissingValuesException.missing_values(zerovallist)
else:
    return True

This blocks assessors from saving the form with 0 as a value for the fields that shouldn't have that (hardcoded as some numeric fields can have 0s) On attempting to save the form a popup mentions which fields need to be fixed (while staying on the form, which I can't get to happen with the standard FeatureSaveException() as it weirdly flashes back to the main window and then back to the form)

But if I could indicate that those 0-value fields are Required with red text on the form itself while filling it out, rather than finding out only on attempting to save the form, that would be ideal.
Related issues raised on github date back to 2015 and haven't helped me figure it out.

Am still testing this on ROAM 2.7.2 to work with current projects in production while waiting for more stable releases of ROAM 3 (thanks to everyone who has been working on that!)

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

No branches or pull requests

1 participant