multi line paste for add course and edit course

This commit is contained in:
rgrgogu
2026-07-30 20:35:38 +08:00
parent f9616b7219
commit 3ccbda7a00
3 changed files with 47 additions and 5 deletions
@@ -43,7 +43,18 @@ export default function EditLesson() {
defaultValues: { title: "", description: "", order: 0, objectives: [] },
});
const { fields, append, remove } = useFieldArray({ control, name: "objectives" });
const { fields, append, remove, insert, update } = 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();
update(index, { value: lines[0] });
lines.slice(1).forEach((line, i) => {
insert(index + 1 + i, { value: line });
});
};
const { bypassOnce, dialog: unsavedChangesDialog } = useUnsavedChangesGuard(isDirty);
@@ -154,6 +165,7 @@ export default function EditLesson() {
<Input
placeholder={`Objective ${index + 1}`}
{...register(`objectives.${index}.value`)}
onPaste={(e) => handleObjectivePaste(e, index)}
/>
<FieldError message={errors.objectives?.[index]?.value?.message} />
</div>