PromucFlow_constructor/app/client/src/widgets/InputWidgetV2/widget/Utilities.ts
balajisoundar f1d1ee9ac0
fix: numeric type input widget should accept zero after decimal point (#11923)
- Derived properties of List widget children won't work. so having the text
  property of the Input widget as a derived property causes issues. hence
  having it as a meta property.
2022-03-18 22:18:16 +05:30

31 lines
598 B
TypeScript

import { isNil } from "lodash";
import { InputTypes } from "widgets/BaseInputWidget/constants";
/*
* Function to parse text as number based on InputType
* - NUMBER : Number(text)
* - Others: text
*/
export function getParsedText(value: string, inputType: InputTypes) {
let text;
switch (inputType) {
case InputTypes.NUMBER:
if (isNil(value) || value === "") {
text = null;
} else {
text = Number(value);
if (isNaN(text)) {
text = null;
}
}
break;
default:
text = value;
break;
}
return text;
}