USGS-WiM / whispers

Wildlife Health Information Sharing Partnership event reporting system(WHISPers) v2
Other
2 stars 1 forks source link

"Number Assessed" and "Number with this Diagnosis" >= 1 #1262

Closed JChipault closed 1 year ago

JChipault commented 2 years ago

Undesired Design or Confusing behavior Users are able to enter 0s and negative numbers into the "number assessed" and "number with this diagnosis" field. A user can use the down arrow to access 0, and they can type in negative numbers (even though the down arrow won't go below 0).

image

If Possible, Describe a Solution Add business rule such that IF any number is entered, then "number assessed" and "number with this diagnosis" must be 1 or greater. Put another way, these fields can be null, but if someone enters a number it must be 1 or greater.

Change of business rules should be applied to create event (add adding location when creating an event) and event details page (and adding location when editing an event).

Keep business rule that indicates that "Number with this Diagnosis" cannot be higher than "Number Assessed": image

In case it helps.... A similar rule with a floor of 0 is already in place for the sick and dead number fields. Maybe parts of that code could be used? Could we have something similar on the frontend such that when someone tries to enter a 0 or a negative value into the "number assessed" or "number with this diagnosis" field that they get this sort of display: image

BlakeDraper commented 2 years ago

This one is a little tricky because of the way HTML number inputs work. I have added code that prevents any negative number from being entered (automatically converts to absolute value), and I can set the min to 1 which prevents arrowing down to 0, but I cannot prevent someone from typing a 0. Further, for some reason I cannot determine after several hours of banging on it, the form validation for minimum (the red text validation) does not work on this particular component. Absolutely baffling so far. No errors and identical code to other validators so must be some strange outside factor.

BlakeDraper commented 2 years ago

@JChipault I am creating a form-level validation and error message. Do I understand correctly that you want to allow Number Assessed to be 0, but prohibit Number with this Diagnosis from being 0?

Also, do you have a desired text for that validation/error message to the user? I threw this together but I would imagine you have a more informed idea of what it should say:

A species diagnosis record should not exist if no specimens were confirmed to have the diagnosis after assessment. Please enter a number greater than zero to save this record.

JChipault commented 2 years ago

Recording reasoning here.... Valid options would be: assessed = null, with diagnosis = null assessed >= 1, with diagnosis = null assessed = null, with diagnosis >= 1 assessed >= 1, with diagnosis >= 1 (AND <= assessed)

And you can't do this because "number with this diagnosis" has to be <= "number assessed": assessed = 0, with diagnosis >=1

And you can't do these because we don't want "number with this diagnosis" to be 0: assessed = null, with diagnosis = 0 assessed >= 1, with diagnosis = 0 assessed = 0, with diagnosis = 0

Which just leaves this case in question: assessed=0, with diagnosis = null

To keep things simple/unified, let's not allow this "case in question" scenario either, which leaves the top 4 scenarios as the only valid options.

Error message when someone tries to save a new event or tries to add a species diagnosis to an existing event: Number Assessed and Number with this Diagnosis cannot be 0. Leave these fields blank if values are unknown. Please do not use a species diagnosis to capture negative test results, instead enter that information as a comment.

When someone is editing an event, that error message would show up here, right? image

And then there's the other wrinkle that you brought up about HTML needing a Clear button in order for the null to be recognized as null on form submission. I haven't fully wrapped my head around that. Do we need to not allow folks to hit the backspace button but instead make them hit a Clear button or an "x" button? Hopefully not but I want to double check.

BlakeDraper commented 2 years ago

@JChipault

HTML needing a Clear button in order for the null to be recognized as null on form submission

Thankfully I think we can scratch that. I played around more with that and I think I was wrong - something else in the mix was causing that problem. Sorry for the confusion there.

JChipault commented 2 years ago

I really like how this business rule has been flagged for the user. That's working well. Thanks.

I did notice, however, that now the lab field defaults to open and so, if you don't have a lab, you have to click the red minus sign by the empty lab line before you can submit the data. Can we tweak this back to how it is on the live site: user is able to enter only a diagnosis and then click "add" (vs. on the test site, user enters a diagnosis, has to click the minus sign by the lab, and then can click "add").

JChipault commented 2 years ago

Thanks for defaulting the lab field to closed. This looks good now!

BlakeDraper commented 1 year ago

Published in v2.17.0