Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed issue with CreateMultiLingualFormItems not rendering when … #1539

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import { contentLanguageKeyMap } from '../../constants/contentLanguage';
import { Form } from 'antd';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -26,22 +26,26 @@ import MultilingualInput from '../../components/MultilingualInput';

const CreateMultiLingualFormItems = ({ children, ...rest }) => {
const { calendarContentLanguage, form, name, data, required, validations, dataCy, placeholder, entityId } = rest;
Form.useWatch(name[0], form);
const { t } = useTranslation();

// State to track dirty fields
const [isFieldDirty, setIsFieldDirty] = useState({});

let isFieldDirty = {}; // to keep track of dirty fields
let dataCyCollection = [];
let placeholderCollection = [];

const formItemList = calendarContentLanguage.map((language) => {
calendarContentLanguage.forEach((language) => {
const lanKey = contentLanguageKeyMap[language];
const fieldName = name.concat([lanKey]);
isFieldDirty[lanKey] = form.isFieldTouched(fieldName);
});

const formItemList = calendarContentLanguage.map((language) => {
const dependencies = calendarContentLanguage // dependencies for each form item
.filter((lan) => lan !== language)
.map((lan) => [name, contentLanguageKeyMap[lan]]);

dataCyCollection.push(`${dataCy}${language.toLowerCase()}`);
placeholderCollection.push(placeholder[lanKey] ?? '');
placeholderCollection.push(placeholder[contentLanguageKeyMap[language]] ?? '');

const validationRules = required // validation rules for each form item
? [
Expand All @@ -62,21 +66,11 @@ const CreateMultiLingualFormItems = ({ children, ...rest }) => {

return (
<Form.Item
name={[`${name}`, lanKey]}
name={[`${name}`, contentLanguageKeyMap[language]]}
key={language}
dependencies={dependencies}
initialValue={data?.[lanKey]}
rules={validationRules}
shouldUpdate={() => {
const updatedIsFieldDirty = {};
calendarContentLanguage.forEach((language) => {
const lanKey = contentLanguageKeyMap[language];
const fieldName = name.concat([lanKey]);
updatedIsFieldDirty[lanKey] = form.isFieldTouched(fieldName);
});
setIsFieldDirty(updatedIsFieldDirty);
return true;
}}>
initialValue={data?.[contentLanguageKeyMap[language]]}
rules={validationRules}>
{children}
</Form.Item>
);
Expand Down
Loading