mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Improved number input initial value decimal handling
This commit is contained in:
@@ -553,7 +553,7 @@ function RefreshLocaleNumberDisplay(rootSelector = "#page-content")
|
||||
return;
|
||||
}
|
||||
|
||||
$(this).text(parseFloat($(this).text()).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
$(this).text(parseFloat($(this).text()).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
});
|
||||
|
||||
$(rootSelector + " .locale-number.locale-number-quantity-amount").each(function()
|
||||
@@ -578,6 +578,40 @@ function RefreshLocaleNumberDisplay(rootSelector = "#page-content")
|
||||
}
|
||||
RefreshLocaleNumberDisplay();
|
||||
|
||||
function RefreshLocaleNumberInput(rootSelector = "#page-content")
|
||||
{
|
||||
$(rootSelector + " .locale-number-input.locale-number-currency").each(function()
|
||||
{
|
||||
if (isNaN(parseFloat($(this).val())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$(this).val(parseFloat($(this).val()).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
});
|
||||
|
||||
$(rootSelector + " .locale-number-input.locale-number-quantity-amount").each(function()
|
||||
{
|
||||
if (isNaN(parseFloat($(this).val())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$(this).val(parseFloat($(this).val()).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
});
|
||||
|
||||
$(rootSelector + " .locale-number-input.locale-number-generic").each(function()
|
||||
{
|
||||
if (isNaN(parseFloat($(this).val())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$(this).val(parseFloat($(this).val()).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 }));
|
||||
});
|
||||
}
|
||||
RefreshLocaleNumberInput();
|
||||
|
||||
$(document).on("click", ".easy-link-copy-textbox", function()
|
||||
{
|
||||
$(this).select();
|
||||
|
@@ -1 +1,3 @@
|
||||
$("#batteries_due_soon_days").val(Grocy.UserSettings.batteries_due_soon_days);
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
@@ -1 +1,3 @@
|
||||
$("#chores_due_soon_days").val(Grocy.UserSettings.chores_due_soon_days);
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
@@ -97,6 +97,7 @@
|
||||
$("#display_amount").attr("step", "1");
|
||||
$("#display_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '1'));
|
||||
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_consume_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
$("#tare-weight-handling-info").addClass("d-none");
|
||||
Grocy.Components.ProductPicker.Clear();
|
||||
@@ -162,6 +163,7 @@ $('#save-mark-as-open-button').on('click', function(e)
|
||||
toastr.success(__t('Marked %1$s of %2$s as opened', jsonForm.amount + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockTransaction(\'' + result.transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
|
||||
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_consume_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
Grocy.Components.ProductPicker.Clear();
|
||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||
@@ -275,6 +277,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
|
||||
Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_stock.id);
|
||||
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_consume_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
|
||||
$("#location_id").find("option").remove().end().append("<option></option>");
|
||||
@@ -312,6 +315,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
if (BoolVal(Grocy.UserSettings.scan_mode_consume_enabled))
|
||||
{
|
||||
$("#display_amount").val(1);
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm("consume-form");
|
||||
|
@@ -163,6 +163,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
}
|
||||
|
||||
$('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
RefreshLocaleNumberInput();
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
||||
{
|
||||
Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id);
|
||||
@@ -173,6 +174,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
}
|
||||
|
||||
$('#display_amount').val(productDetails.stock_amount);
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
$('#display_amount').focus();
|
||||
$('#display_amount').trigger('keyup');
|
||||
|
@@ -777,6 +777,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
|
||||
|
||||
$('#display_amount').val(1);
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
$('#display_amount').focus();
|
||||
$('#display_amount').select();
|
||||
|
@@ -256,6 +256,9 @@ $("#allow_partial_units_in_stock").on("click", function()
|
||||
$("#qu_factor_purchase_to_stock").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1");
|
||||
$("#qu_factor_purchase_to_stock").attr("step", "." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1");
|
||||
$("#qu_factor_purchase_to_stock").parent().find(".invalid-feedback").text(__t('This cannot be lower than %1$s and must be a valid number with max. %2$s decimal places', "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1", Grocy.UserSettings.stock_decimal_places_amounts));
|
||||
$("#quick_consume_amount").attr("min", "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1");
|
||||
$("#quick_consume_amount").attr("step", "." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1");
|
||||
$("#quick_consume_amount").parent().find(".invalid-feedback").text(__t('This cannot be lower than %1$s and must be a valid number with max. %2$s decimal places', "0." + "0".repeat(parseInt(Grocy.UserSettings.stock_decimal_places_amounts) - 1) + "1", Grocy.UserSettings.stock_decimal_places_amounts));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -264,6 +267,9 @@ $("#allow_partial_units_in_stock").on("click", function()
|
||||
$("#qu_factor_purchase_to_stock").attr("min", "1");
|
||||
$("#qu_factor_purchase_to_stock").attr("step", "1");
|
||||
$("#qu_factor_purchase_to_stock").parent().find(".invalid-feedback").text(__t('This cannot be lower than %1$s and must be a valid number with max. %2$s decimal places', '1', '0'));
|
||||
$("#quick_consume_amount").attr("min", "1");
|
||||
$("#quick_consume_amount").attr("step", "1");
|
||||
$("#quick_consume_amount").parent().find(".invalid-feedback").text(__t('This cannot be lower than %1$s and must be a valid number with max. %2$s decimal places', '1', '0'));
|
||||
}
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm("product-form");
|
||||
|
@@ -204,7 +204,15 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
||||
}
|
||||
|
||||
$('#price').val(parseFloat(productDetails.last_price / $("#qu_id option:selected").attr("data-qu-factor")).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
if (productDetails.last_price == null)
|
||||
{
|
||||
$("#price").val("")
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#price').val(parseFloat(productDetails.last_price / $("#qu_id option:selected").attr("data-qu-factor")).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }));
|
||||
RefreshLocaleNumberInput();
|
||||
}
|
||||
|
||||
var priceTypeUnitPrice = $("#price-type-unit-price");
|
||||
var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
|
||||
@@ -267,6 +275,7 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
|
||||
{
|
||||
$("#display_amount").val(1);
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
|
||||
Grocy.FrontendHelpers.ValidateForm("purchase-form");
|
||||
@@ -332,6 +341,7 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
}
|
||||
|
||||
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
||||
|
||||
|
@@ -2,3 +2,5 @@
|
||||
{
|
||||
$("#recipe_ingredients_group_by_product_group").prop("checked", true);
|
||||
}
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
@@ -212,6 +212,7 @@ if (GetUriParam("list") !== undefined)
|
||||
if (GetUriParam("amount") !== undefined)
|
||||
{
|
||||
$("#display_amount").val(parseFloat(GetUriParam("amount")).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
|
||||
}
|
||||
|
@@ -7,3 +7,5 @@ if (BoolVal(Grocy.UserSettings.shopping_list_show_calendar))
|
||||
{
|
||||
$("#shopping-list-show-calendar").prop("checked", true);
|
||||
}
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
@@ -109,6 +109,8 @@ Grocy.Api.Get('stock/products/' + Grocy.EditObjectProductId,
|
||||
$("#amount").attr("step", "1");
|
||||
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %1$s', '1'));
|
||||
}
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
|
@@ -20,3 +20,5 @@ if (BoolVal(Grocy.UserSettings.show_warning_on_purchase_when_best_before_date_is
|
||||
{
|
||||
$("#show_warning_on_purchase_when_best_before_date_is_earlier_than_next").prop("checked", true);
|
||||
}
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
@@ -1 +1,3 @@
|
||||
$("#tasks_due_soon_days").val(Grocy.UserSettings.tasks_due_soon_days);
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
@@ -94,6 +94,7 @@
|
||||
$("#display_amount").attr("step", "1");
|
||||
$("#display_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '1'));
|
||||
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_transfer_amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }));
|
||||
RefreshLocaleNumberInput();
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
$("#tare-weight-handling-info").addClass("d-none");
|
||||
Grocy.Components.ProductPicker.Clear();
|
||||
|
@@ -1 +1,3 @@
|
||||
$("#locale").val(Grocy.UserSettings.locale);
|
||||
|
||||
RefreshLocaleNumberInput();
|
||||
|
Reference in New Issue
Block a user