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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user