fix drag and drop
This commit is contained in:
parent
2915d85fcf
commit
b18e139445
|
|
@ -102,7 +102,9 @@ const AddPage: React.FC = () => {
|
|||
{ resetForm }: { resetForm: () => void },
|
||||
) => {
|
||||
const DataToSend = structuredClone(values);
|
||||
|
||||
console.log(DataToSend);
|
||||
|
||||
return ;
|
||||
setTagsSearch(null);
|
||||
const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0;
|
||||
if (isBseQuestion || DataToSend?.isBase === 1) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ const CheckboxField = ({
|
|||
const formik = useFormikContext<any>();
|
||||
const [t] = useTranslation();
|
||||
const CheckboxhandleChange = (value: any) => {
|
||||
console.log(value?.target?.checked);
|
||||
|
||||
const allAreZero = formik?.values?.Questions?.[
|
||||
parent_index
|
||||
|
|
|
|||
|
|
@ -9,18 +9,25 @@ const Choices = ({ parent_index }: { parent_index: number }) => {
|
|||
|
||||
const handleDragEnd = (result: any) => {
|
||||
// Check if the item was dropped outside the list
|
||||
console.log(1);
|
||||
console.log(result.destination);
|
||||
|
||||
if (!result.destination) return;
|
||||
|
||||
console.log(formik?.values?.Questions?.[parent_index]?.QuestionOptions);
|
||||
|
||||
// Create a new array from the current QuestionOptions
|
||||
const items = Array.from(formik?.values?.QuestionOptions);
|
||||
|
||||
const items = Array.from(formik?.values?.Questions?.[parent_index]?.QuestionOptions);
|
||||
console.log(items);
|
||||
// Remove the item from the original position
|
||||
const [reorderedItem] = items.splice(result.source.index, 1);
|
||||
|
||||
console.log(items);
|
||||
// Insert the item at the new position
|
||||
items.splice(result.destination.index, 0, reorderedItem);
|
||||
|
||||
// Update the order keys based on the new indices
|
||||
console.log(items,"items");
|
||||
|
||||
const updatedItems = items.map((item, index) => ({
|
||||
...(item ?? {}),
|
||||
order: index + 1, // Update order to be 1-based index
|
||||
|
|
@ -29,7 +36,7 @@ const Choices = ({ parent_index }: { parent_index: number }) => {
|
|||
// Update the formik state with the new order
|
||||
console.log(updatedItems, "updatedItems");
|
||||
|
||||
formik.setFieldValue("QuestionOptions", updatedItems);
|
||||
formik.setFieldValue(`Questions.${parent_index}.QuestionOptions`, updatedItems);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ const CheckboxField = ({
|
|||
const formik = useFormikContext<any>();
|
||||
const [t] = useTranslation();
|
||||
const newName = `Questions[${name}].canAnswersBeShuffled`;
|
||||
console.log(formik.values?.Questions?.[name]);
|
||||
|
||||
const CheckboxhandleChange = (value: any, index: number) => {
|
||||
formik.setFieldValue(newName, value?.target?.checked ? 1 : 0);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ const DynamicTags = () => {
|
|||
name: TagsSearch,
|
||||
});
|
||||
const suggests = data?.data;
|
||||
console.log(TagsSearch);
|
||||
|
||||
const handleAddChoice = () => {
|
||||
const length = formik?.values?.tags.length;
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@
|
|||
"question": "السؤال",
|
||||
"id": "الرقم التعريفي",
|
||||
"canAnswersBeShuffled": "يمكن خلط الإجابات",
|
||||
"hint": "لحليح"
|
||||
"hint": "تَلمِيح"
|
||||
},
|
||||
|
||||
"select": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user