multi line paste for add course and edit course

This commit is contained in:
rgrgogu
2026-07-30 20:11:32 +08:00
parent 04c4a3e1f6
commit f9616b7219
9 changed files with 35 additions and 10 deletions
+13 -1
View File
@@ -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>