All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.components.ObjectValidation.ErrorMessage.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 {Card, RadioField} from '@liferay/object-js-components-web';
import {InputLocalized} from 'frontend-js-components-web';
import React from 'react';

import {ObjectValidationErrors} from './useObjectValidationForm';

const outputValidationTypeArray = [
	{
		label: Liferay.Language.get('full-validation-form-summary'),
		value: 'fullValidation',
	},
	{
		label: Liferay.Language.get('partial-validation-inline-field'),
		value: 'partialValidation',
	},
];

interface ErrorMessageProps {
	children: React.ReactNode;
	disabled: boolean;
	errors: ObjectValidationErrors;
	setValues: (values: Partial) => void;
	values: Partial;
}

export function ErrorMessage({
	children,
	disabled,
	errors,
	setValues,
	values,
}: ErrorMessageProps) {
	return (
		
			 setValues({errorLabel})}
				placeholder={Liferay.Language.get('add-an-error-message')}
				required
				translations={values.errorLabel!}
			/>

			 {
					if (value === 'fullValidation') {
						setValues({
							objectValidationRuleSettings:
								values.engine === 'compositeKey'
									? values.objectValidationRuleSettings?.filter(
											(objectValidationRuleSetting) =>
												objectValidationRuleSetting.name ===
												'compositeKeyObjectFieldExternalReferenceCode'
										)
									: [],
							outputType: value as string,
						});

						return;
					}
					else if (
						value === 'partialValidation' &&
						values.engine === 'compositeKey'
					) {
						const outputObjectFieldExternalReferenceCode =
							values.objectValidationRuleSettings?.map(
								(objectValidationRuleSetting) => {
									return {
										name: 'outputObjectFieldExternalReferenceCode',
										value: objectValidationRuleSetting.value,
									};
								}
							) as ObjectValidationRuleSetting[];

						setValues({
							objectValidationRuleSettings:
								values.objectValidationRuleSettings?.concat(
									outputObjectFieldExternalReferenceCode
								),
							outputType: value as string,
						});

						return;
					}

					setValues({
						outputType: value as string,
					});
				}}
				options={outputValidationTypeArray}
				popover={{
					alignPosition: 'top',
					content: Liferay.Language.get(
						'map-the-error-message-to-be-displayed-next-to-the-validated-field'
					),
					header: Liferay.Language.get('message-location'),
				}}
			/>

			{values.outputType === 'partialValidation' && children}
		
	);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy