
META-INF.resources.js.components.ObjectField.AutoIncrementFormBase.tsx Maven / Gradle / Ivy
The newest version!
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import {Input} from '@liferay/object-js-components-web';
import React from 'react';
import {ObjectFieldErrors} from './ObjectFieldFormBase';
import './AutoIncrementFormBase.scss';
interface AutoIncrementFormBaseProps {
disabled: boolean;
errors: ObjectFieldErrors;
modelBuilder?: boolean;
onSubmit?: (values?: Partial) => void;
setValues: (values: Partial) => void;
values: Partial;
}
const PREFIX_SUFFIX_REGEX = /^[a-zA-Z0-9 /:,.()[\]{}#$%+-]*$/;
export function AutoIncrementFormBase({
disabled,
errors,
modelBuilder,
onSubmit,
setValues,
values,
}: AutoIncrementFormBaseProps) {
return (
{
event.stopPropagation();
if (onSubmit) {
onSubmit();
}
}}
onChange={({target: {value}}) => {
const regexValidation = PREFIX_SUFFIX_REGEX.exec(value);
if (regexValidation !== null) {
setValues({
objectFieldSettings: [
...(values.objectFieldSettings?.filter(
(objectFieldSetting) =>
objectFieldSetting.name !== 'prefix'
) as ObjectFieldSetting[]),
{
name: 'prefix',
value,
},
],
});
}
}}
value={
(values.objectFieldSettings?.find(
(objectFieldSetting) =>
objectFieldSetting.name === 'prefix'
)?.value as string) ?? ''
}
/>
{
event.stopPropagation();
if (onSubmit) {
onSubmit();
}
}}
onChange={({target: {value}}) => {
setValues({
objectFieldSettings: [
...(values.objectFieldSettings?.filter(
(objectFieldSetting) =>
objectFieldSetting.name !== 'initialValue'
) as ObjectFieldSetting[]),
{
name: 'initialValue',
value,
},
],
});
}}
onKeyDown={(event) => {
if (event.key === '.' || event.key === '-') {
event.preventDefault();
}
}}
required
tooltip={Liferay.Language.get(
'set-the-initial-numeric-value-to-increment-this-value-cannot-be-less-than-1'
)}
type="number"
value={
(values.objectFieldSettings?.find(
(objectFieldSetting) =>
objectFieldSetting.name === 'initialValue'
)?.value as string) ?? ''
}
/>
{
event.stopPropagation();
if (onSubmit) {
onSubmit();
}
}}
onChange={({target: {value}}) => {
const regexValidation = PREFIX_SUFFIX_REGEX.exec(value);
if (regexValidation !== null) {
setValues({
objectFieldSettings: [
...(values.objectFieldSettings?.filter(
(objectFieldSetting) =>
objectFieldSetting.name !== 'suffix'
) as ObjectFieldSetting[]),
{
name: 'suffix',
value,
},
],
});
}
}}
value={
(values.objectFieldSettings?.find(
(objectFieldSetting) =>
objectFieldSetting.name === 'suffix'
)?.value as string) ?? ''
}
/>
);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy