Open IsaacJrTypes opened 2 months ago
Thanks for this.
I'd rather keep the duplicateNameError
observable on the Variable
object.
You could avoid resetting the duplicateNameError
by running through in two passes:
Variable
object, set duplicateNameError
to null
.duplicateNameError
if the group has more than one element and duplicateNameError
is not already non-null.@christianp Thank you for the feedback! I updated the code to your suggestions.
Around line 2005, I subscribed to the Variable
object's duplicateNameError
observable to console.log the state of the observable.
Any additional feedback is welcomed. I can also remove the comments if you think they aren't necessary.
@IsaacJrTypes Thanks. This isn't quite correct: it only sets the error message on the first Variable
object for each repeated name.
I'll add some aesthetic comments to the code as well.
The following code fixes the duplicate warning logic. Previously, the duplicate error logic would sort the names of the entries in the names input field, turn them into variable objects, and group them. Each group would be processed by the handle_group function, which would trigger updating the duplicateNameError knock-out observable if there more than 1 object in the group. The issue with this method is if the user inputs
a,b,a
, thea
group would trigger the duplicateNameError function, but once theb
group is processed, the duplicateNameError observable updates tonull
.I used an object to track if there were any duplicates. Each time the user updates input names, a new object is created, and if there are duplicates, it returns the name error message.![CleanShot 2024-05-14 at 16 28 07](https://github.com/numbas/editor/assets/36749051/1982d76e-88b2-4f84-87c4-0fbaaee4d6b8)