mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
multi line paste for add course and edit course
This commit is contained in:
@@ -181,8 +181,19 @@ export default function AddCourse() {
|
||||
},
|
||||
});
|
||||
|
||||
const { fields: objectiveFields, append: appendObjective, remove: removeObjective } =
|
||||
const { fields: objectiveFields, append: appendObjective, remove: removeObjective, insert: insertObjective } =
|
||||
useFieldArray({ control, name: "objectives" });
|
||||
|
||||
const handleObjectivePaste = (e, index) => {
|
||||
const text = e.clipboardData.getData("text");
|
||||
const lines = text.split(/\r\n|\r|\n/).map((l) => l.trim()).filter(Boolean);
|
||||
if (lines.length <= 1) return;
|
||||
e.preventDefault();
|
||||
setValue(`objectives.${index}.text`, lines[0], { shouldDirty: true, shouldValidate: true });
|
||||
lines.slice(1).forEach((line, i) => {
|
||||
insertObjective(index + 1 + i, { text: line });
|
||||
});
|
||||
};
|
||||
const { fields: roleFields, append: appendRole, remove: removeRole } =
|
||||
useFieldArray({ control, name: "roles" });
|
||||
|
||||
@@ -415,6 +426,7 @@ export default function AddCourse() {
|
||||
<Input
|
||||
placeholder={`Objective ${index + 1}`}
|
||||
{...register(`objectives.${index}.text`)}
|
||||
onPaste={(e) => handleObjectivePaste(e, index)}
|
||||
/>
|
||||
<FieldError message={errors.objectives?.[index]?.text?.message} />
|
||||
</div>
|
||||
|
||||
@@ -239,8 +239,19 @@ export default function EditCourse() {
|
||||
},
|
||||
});
|
||||
|
||||
const { fields: objectiveFields, append: appendObjective, remove: removeObjective } =
|
||||
const { fields: objectiveFields, append: appendObjective, remove: removeObjective, insert: insertObjective } =
|
||||
useFieldArray({ control, name: "objectives" });
|
||||
|
||||
const handleObjectivePaste = (e, index) => {
|
||||
const text = e.clipboardData.getData("text");
|
||||
const lines = text.split(/\r\n|\r|\n/).map((l) => l.trim()).filter(Boolean);
|
||||
if (lines.length <= 1) return;
|
||||
e.preventDefault();
|
||||
setValue(`objectives.${index}.text`, lines[0], { shouldDirty: true, shouldValidate: true });
|
||||
lines.slice(1).forEach((line, i) => {
|
||||
insertObjective(index + 1 + i, { text: line });
|
||||
});
|
||||
};
|
||||
const { fields: roleFields, append: appendRole, remove: removeRole } =
|
||||
useFieldArray({ control, name: "roles" });
|
||||
|
||||
@@ -675,6 +686,7 @@ export default function EditCourse() {
|
||||
<Input
|
||||
placeholder={`Objective ${index + 1}`}
|
||||
{...register(`objectives.${index}.text`)}
|
||||
onPaste={(e) => handleObjectivePaste(e, index)}
|
||||
/>
|
||||
<FieldError message={errors.objectives?.[index]?.text?.message} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user