2020-04-28 06:52:53 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import { InputType } from "widgets/InputWidget";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
|
|
|
|
import TextField from "components/editorComponents/form/fields/TextField";
|
2020-08-05 08:02:24 +00:00
|
|
|
import FormLabel from "components/editorComponents/FormLabel";
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
export function InputText(props: {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
isValid: boolean;
|
|
|
|
|
validationMessage?: string;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
dataType?: string;
|
|
|
|
|
isRequired?: boolean;
|
|
|
|
|
name: string;
|
|
|
|
|
}) {
|
2020-08-05 08:02:24 +00:00
|
|
|
const { name, placeholder, dataType, label, isRequired } = props;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
return (
|
2020-10-15 11:38:55 +00:00
|
|
|
<div style={{ width: "50vh" }} data-cy={name}>
|
2020-08-05 08:02:24 +00:00
|
|
|
<FormLabel>
|
|
|
|
|
{label} {isRequired && "*"}
|
|
|
|
|
</FormLabel>
|
2020-04-28 06:52:53 +00:00
|
|
|
<TextField
|
|
|
|
|
name={name}
|
|
|
|
|
placeholder={placeholder}
|
|
|
|
|
type={dataType}
|
|
|
|
|
showError
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class InputTextControl extends BaseControl<InputControlProps> {
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
validationMessage,
|
|
|
|
|
propertyValue,
|
|
|
|
|
isValid,
|
|
|
|
|
label,
|
|
|
|
|
placeholderText,
|
|
|
|
|
dataType,
|
|
|
|
|
configProperty,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<InputText
|
|
|
|
|
name={configProperty}
|
|
|
|
|
label={label}
|
|
|
|
|
value={propertyValue}
|
|
|
|
|
isValid={isValid}
|
|
|
|
|
validationMessage={validationMessage}
|
|
|
|
|
placeholder={placeholderText}
|
|
|
|
|
dataType={this.getType(dataType)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isNumberType(): boolean {
|
|
|
|
|
const { inputType } = this.props;
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case "CURRENCY":
|
|
|
|
|
case "INTEGER":
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
case "PHONE_NUMBER":
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getType(dataType: InputType | undefined) {
|
|
|
|
|
switch (dataType) {
|
|
|
|
|
case "PASSWORD":
|
|
|
|
|
return "password";
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
return "number";
|
|
|
|
|
default:
|
|
|
|
|
return "text";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "INPUT_TEXT";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputControlProps extends ControlProps {
|
|
|
|
|
placeholderText: string;
|
|
|
|
|
inputType?: InputType;
|
|
|
|
|
dataType?: InputType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InputTextControl;
|