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

Support decimal numbers in editor #1051

Open
elaygl opened this issue Jan 6, 2019 · 2 comments
Open

Support decimal numbers in editor #1051

elaygl opened this issue Jan 6, 2019 · 2 comments

Comments

@elaygl
Copy link
Contributor

elaygl commented Jan 6, 2019

Tweek editor doesn't support decimal values only through the Source tab

@tal952
Copy link
Contributor

tal952 commented Jan 6, 2019

The problem is here:

https://github.com/Soluto/tweek/blob/master/services/editor/src/components/common/Input/TypedInput.js#L141

const TypedInput = compose(
  connect(null, {
    showCustomAlert,
  }),
  getTypesService,
  mapProps(
    ({
      safeConvertValue,
      types,
      isAllowedValue,
      valueType,
      onChange,
      showCustomAlert,
      ...props
    }) => {
      valueType = (typeof valueType === 'string' ? types[valueType] : valueType) || {
        name: 'unknown',
      };
      const onChangeConvert = newValue =>
        onChange && onChange(safeConvertValue(newValue, valueType));
      const valueTypeName = valueType.name || valueType.base;
      return {
        allowedValues: valueType.allowedValues,
        onChange: onChangeConvert,
        valueType,
        valueTypeName,
        types,
        ...props,
      };
    },
  ),
)(InputWithIcon);

The safeConvertValue is reseting the number when we add the dot.
We can use onBlur here (The onblur event occurs when an object loses focus).
Maybe when we validate it on the onChange event it will accept value as "1.", and on onBlur event we will add a "0" to the "1." so it will become "1.0".
What do you think?

@Yshayy
Copy link
Contributor

Yshayy commented Jan 18, 2019

I think it makes sense to use the onBlur, but it might break behavior somewhere else (as it's typedInput), maybe add if valueType === 'number' and newValue end with "." add zero. (inside safeConvertValue)

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

No branches or pull requests

3 participants