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

Count is allowed to be less than or equals to zero #691

Open
HeLinChooi opened this issue Jun 18, 2023 · 3 comments
Open

Count is allowed to be less than or equals to zero #691

HeLinChooi opened this issue Jun 18, 2023 · 3 comments
Labels

Comments

@HeLinChooi
Copy link

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Click “Quick forms”.
  2. Click “Planting” tab.
  3. Click “Season” field input and inputs “summer”.
  4. Click “Crop/variety” and inputs “corn”.
  5. Select a location for the “Location” input.
  6. Open “Quantity” drop down.
  7. Choose “Measure” to “count”.
  8. Click “Value” and inputs “-1”.
  9. Click “Submit” button.

Expected behavior
The system displays error message “The count value can’t be zero or negative”.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 114.0.5735.134 (Official Build) (64-bit)

Additional context
Add any other context about the problem here.

@HeLinChooi HeLinChooi added the bug label Jun 18, 2023
@mstenta
Copy link
Member

mstenta commented Jun 18, 2023

Thanks @HeLinChooi - I agree negative numbers shouldn't be allowed in this quick form (or in other quick forms for that matter).

However, I think zero should be allowed. Someone may use that as a placeholder for a log that hasn't happened yet, and that they plan to fill in with an actual value later.

Would you like to start a pull request for adding validation to prevent negative numbers? It should be fairly simple. I think we just need to change the input form element from '#type' => 'textfield' to '#type' => 'number' add '#min' => 0, so that it can't be negative.

https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Number.php/class/Number/8.2.x

Here is the form element in the code: https://github.com/farmOS/farmOS/blob/2.x/modules/quick/planting/src/Plugin/QuickForm/Planting.php#LL361C7-L361C7

There are other quick forms that we might want to do the same to, but if you want to just start with a PR for that one I can help with the others.

@wotnak
Copy link
Collaborator

wotnak commented Jun 18, 2023

Quantity value field in the quantity entity form (displayed for example in the log entity form) uses fraction_decimal input element type that adds some additional validation that the given value is a valid fraction. Maybe it would be a good idea to also use it in the quick forms. Although it would complicate adding validation that value is not negative since fraction_decimal type doesn't currently support setting the #min value.

@mstenta
Copy link
Member

mstenta commented Jun 18, 2023

Hmm yea that makes sense. Perhaps we need two new PRs: one for fraction (to add min/max) and one for farmOS (to use fraction_decimal in quick forms).

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

No branches or pull requests

3 participants