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

adjustToValidValues() from PriceRange customElement fails when data-max / data-min value is formatted with a , #3666

Open
HendrikShopify opened this issue Nov 9, 2024 · 0 comments

Comments

@HendrikShopify
Copy link

Describe the current behavior

This function fails when the data-max and data-min values from the input field are formatted with a , instead of a .

from facets.js asset:

`adjustToValidValues(input) {
// Normalize the value by replacing commas with periods
const normalizedValue = input.value.replace(/,/g, '.');
const value = Number(normalizedValue);
const min = Number(input.getAttribute('data-min'));
const max = Number(input.getAttribute('data-max'));

if (value < min) input.value = min;
if (value > max) input.value = max;

}`

The result of min and max variable are NaN.

from price-facet.liquid snippet:

<input
    class="field__input"
    name="{{ filter.max_value.param_name }}"
    id="{{ id_prefix }}{{ filter.label | escape }}-LTE"
    {%- if filter.max_value.value -%}
      value="{{ filter.max_value.value | money_without_currency }}"
    {%- endif -%}
    type="text"
    inputmode="decimal"
    placeholder="{{ filter.range_max | money_without_currency }}"
    data-pattern="\d| |,|\."
    data-min="0"
    data-max="{{ filter.range_max | money_without_currency"
  >

Describe the expected behavior

The result of min and max variable are formatted as a number.

Version information (Dawn, browsers and operating systems)

  • Dawn Version: 7.0.1
  • Chrome Version 108.0.5359.124
  • macOS Version 13.1

Possible solution

add | replace: ",", "." }} to the data-max and data-min values.

example:

<input
    class="field__input"
    name="{{ filter.max_value.param_name }}"
    id="{{ id_prefix }}{{ filter.label | escape }}-LTE"
    {%- if filter.max_value.value -%}
      value="{{ filter.max_value.value | money_without_currency | replace: ",", "." }} }}"
    {%- endif -%}
    type="text"
    inputmode="decimal"
    placeholder="{{ filter.range_max | money_without_currency }}"
    data-pattern="\d| |,|\."
    data-min="0"
    data-max="{{ filter.range_max | money_without_currency | replace: ",", "." }}"
  >

Additional context/screenshots

Before using | replace: ",", "." }}
Image

After using | replace: ",", "." }}

Image

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