Closed qiaolb closed 2 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.
Hi @qiaolb, taking a look at this. Agreed that there are use cases where preserving the leading zero is significant. A couple thoughts:
Create Data
component does not allow the appropriate flexibility when defining the type of the schema. The value
is automatically interpreted based on the content of the field, meaning that a value such as 001
is interpreted as an integer (and we "helpfully" strip those leading zeros, since int(1)==int(001)
).
001
as a string
, preserving those leading zeros. 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!
@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.
Describe the bug While utilizing the
Create Data
andUpdate 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