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

Editing Salt/Sodium content field does not work correctly with fractions without leading zero #6717

Closed
aquilax opened this issue Apr 29, 2022 · 2 comments · Fixed by #9337 or #9387
Closed
Labels
🐛 bug This is a bug, not a feature request. ✏️ Editing - Nutrition JavaScript 🧂 Salt ⏰ Stale This issue hasn't seen activity in a while. You can try documenting more to unblock it.

Comments

@aquilax
Copy link
Contributor

aquilax commented Apr 29, 2022

Describe the bug

On the product edit page, setting fractional salt or sodium value without leading zero produces incorrect calculated value for the corresponding field.

To Reproduce

  1. Open a product edit page
  2. Set Salt content to .53 and move to the next field
  3. Sodium content is calculated as .21.200000000000003

Expected behavior

Calculation to work without setting leading zero to the fraction.

Screenshots

Screenshot_2022-04-29_10-07-34

Additional context

	function swapSalt(from, to, multiplier) {
		var source = from.val().replace(",", ".");
		var regex = /^(.*?)([\d]+(?:\.[\d]+)?)(.*?)$/g;
		var match = regex.exec(source);
		if (match) {
			var target = match[1] + (parseFloat(match[2]) * multiplier) + match[3];
			to.val(target);
		} else {
			to.val(from.val());
		}
	}

The swap salt function concatenates match[1] in front of the result which leads to having the decimal point twice.

Type of device

Browser

Browser version

Version 100.0.4896.127 (Official Build) (64-bit)

Number of products impacted

No response

Time per product

No response

@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity.

@github-actions github-actions bot added the ⏰ Stale This issue hasn't seen activity in a while. You can try documenting more to unblock it. label Jul 29, 2022
@danwyk
Copy link
Collaborator

danwyk commented Nov 14, 2023

@teolemon I can work on this. Can you assign this bug to me.

danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 18, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 18, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 18, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 18, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 18, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 21, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 21, 2023
danwyk added a commit to danwyk/openfoodfacts-server that referenced this issue Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug This is a bug, not a feature request. ✏️ Editing - Nutrition JavaScript 🧂 Salt ⏰ Stale This issue hasn't seen activity in a while. You can try documenting more to unblock it.
Projects
4 participants