tp-react-elements-dev 1.4.9 → 1.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -52268,14 +52268,25 @@ const SingleSelectNonAutoComplete = ({ props }) => {
52268
52268
  };
52269
52269
 
52270
52270
  const FormActiveSwitch = ({ props }) => {
52271
- const [active, setActive] = React$1.useState(props.getValues(props.item.name)); // Assuming "Active" is the default
52272
- const handleSwitchChange = () => {
52273
- setActive(!active);
52274
- };
52271
+ const { getValues, setValue, item } = props;
52272
+ const [active, setActive] = React$1.useState(true);
52273
+ const data = getValues(item.name);
52275
52274
  React$1.useEffect(() => {
52276
- props.setValue(props.item.name, active);
52277
- }, [active]);
52278
- return (jsxRuntimeExports.jsx("div", { children: jsxRuntimeExports.jsxs("div", Object.assign({ className: "m-form__input" }, { children: [props.item.label && jsxRuntimeExports.jsx("span", Object.assign({ style: { fontSize: "12px", fontWeight: 400, paddingRight: 10 } }, { children: props.item.label })), jsxRuntimeExports.jsxs("span", Object.assign({ className: "switch prestashop-switch fixed-width-lg" }, { children: [jsxRuntimeExports.jsx("input", { checked: active, id: props.item.name + '_on', name: props.item.name, type: "radio", value: "Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: props.item.name + '_on', style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: props.item.label1 ? props.item.label1 : 'Active' })), jsxRuntimeExports.jsx("input", { id: props.item.name + '_off', checked: !active, name: props.item.name, type: "radio", value: "In Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: props.item.name + '_off', style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: props.item.label2 ? props.item.label2 : 'In Active' })), jsxRuntimeExports.jsx("a", { className: "slide-button btn" })] }))] })) }));
52275
+ if (data === undefined || data === null) {
52276
+ setActive(false);
52277
+ }
52278
+ else {
52279
+ setActive(data);
52280
+ }
52281
+ }, [data]);
52282
+ const handleSwitchChange = React$1.useCallback(() => {
52283
+ setActive(prevActive => {
52284
+ // const newValue = !prevActive ? "A" : "I";
52285
+ setValue(item.name, !prevActive);
52286
+ return !prevActive;
52287
+ });
52288
+ }, [setValue, item.name]);
52289
+ return (jsxRuntimeExports.jsx("div", { children: jsxRuntimeExports.jsxs("div", Object.assign({ className: "m-form__input" }, { children: [item.label && (jsxRuntimeExports.jsx("span", Object.assign({ style: { fontSize: "12px", fontWeight: 400, paddingRight: 10 } }, { children: item.label }))), jsxRuntimeExports.jsxs("span", Object.assign({ className: "switch prestashop-switch fixed-width-lg" }, { children: [jsxRuntimeExports.jsx("input", { checked: active, id: `${item.name}_on`, name: item.name, type: "radio", value: "Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: `${item.name}_on`, style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: item.label1 ? item.label1 : "Active" })), jsxRuntimeExports.jsx("input", { checked: !active, id: `${item.name}_off`, name: item.name, type: "radio", value: "In Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: `${item.name}_off`, style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: item.label2 ? item.label2 : "In Active" })), jsxRuntimeExports.jsx("a", { className: "slide-button btn" })] }))] })) }));
52279
52290
  };
52280
52291
 
52281
52292
  const renderLabel = (label, isRequired, alignRight) => {
@@ -52720,7 +52731,19 @@ const RenderForm = (props) => {
52720
52731
  },
52721
52732
  }, minRows: props.item.minRows || 1,
52722
52733
  // maxRows={2}
52723
- placeholder: props.item.placeholder || "Type Something..." }, field, { label: `${props.item.label}${props.item.required ? ' *' : ''}`, value: field.value || "", disabled: props.item.disable })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })) }) }));
52734
+ placeholder: props.item.placeholder || "Type Something..." }, field, { label: `${props.item.label}${props.item.required ? ' *' : ''}`, value: field.value || "", disabled: props.item.disable, inputProps: {
52735
+ onInput: (e) => {
52736
+ var _a;
52737
+ if (!((_a = props === null || props === void 0 ? void 0 : props.item) === null || _a === void 0 ? void 0 : _a.allowSpecialChars)) {
52738
+ const value = e.target.value;
52739
+ e.target.value = value.replace(/[^a-zA-Z0-9 ]/g, "");
52740
+ } // Allow only alphanumeric and space
52741
+ if (e.target.value.length === 1 &&
52742
+ e.target.value === " ") {
52743
+ e.target.value = "";
52744
+ }
52745
+ },
52746
+ } })), jsxRuntimeExports.jsx(ErrorMessageComponent, { children: jsxRuntimeExports.jsx(s, { errors: props.errors, name: props.item.name }) })] })) }) }));
52724
52747
  // case "textarea-normal":
52725
52748
  // return (
52726
52749
  // <>