langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
32.63k stars 3.99k forks source link

Issue with Leading Zeros in Numeric Input for Create Data and Update Data Components #2702

Closed qiaolb closed 2 months ago

qiaolb commented 3 months ago

Describe the bug While utilizing the Create Data and Update Data components for data encapsulation, I have encountered an issue where numeric values that begin with a zero are automatically stripped of their leading zeros. For instance, the number '029' is incorrectly transformed into '29'. This behavior is problematic as it can lead to data inconsistency and errors in applications that rely on the preservation of leading zeros for significance or formatting purposes.

Browser and Version

dosubot[bot] commented 3 months ago

To address the issue of leading zeros being stripped from numeric values in the Create Data and Update Data components, you need to ensure that these values are treated as strings rather than numbers. This can be achieved by modifying the onChange handlers to handle the input as strings.

Here is an example of how you can modify the onChange handlers for the InputComponent to treat the values as strings:

<Case
  condition={
    !node.data.node.template[templateField].multiline &&
    !node.data.node.template[templateField].list
  }
>
  <InputComponent
    editNode={true}
    disabled={false}
    password={node.data.node.template[templateField].password ?? false}
    value={
      !node.data.node.template[templateField].value ||
      node.data.node.template[templateField].value === ""
        ? ""
        : node.data.node.template[templateField].value
    }
    onChange={(target) => {
      setData((old) => {
        let newInputList = cloneDeep(old);
        newInputList![i].data.node.template[templateField].value = target; // Ensure value is treated as string
        return newInputList;
      });
    }}
  />
</Case>

By ensuring that the value is treated as a string, you can prevent the leading zeros from being stripped. This approach should be applied to all relevant input components where numeric values might be entered [1].

To continue talking to Dosu, mention @dosu.

jordanrfrazier commented 2 months ago

Hi @qiaolb, taking a look at this. Agreed that there are use cases where preserving the leading zero is significant. A couple thoughts:

So, hopefully your use case would allow the value to be stored as a string, which would preserve the leading zeros. I'll sync up with the team to see when we will allow that more flexible schema definition. If you'd like to share some specific use cases, it may help us finalize that work and ensure it fits what you need. Thanks!

carlosrcoelho commented 2 months ago

@qiaolb

Thank you for your contribution! This issue will be closed. If you have any questions or encounter another problem, please open a new issue and we will be ready to assist you.