Closed kailichiang closed 1 year ago
I pulled this code down and played with it. It does work to prevent duplicate device names. However, I think it would be a better user experience if the user was given a chance to correct the device name instead of just seeing an error message. For example, when a user is creating a device named "Test" and they click "Add Device," instead of the modal closing and the flash message being displayed, they should get a validation error within the modal where they can change the device name to something else without losing the rest of their settings.
About "better experience," there are several possible solutions.
Solution 1 and 3 probably needs lots engineering, I'm not sure. You may have more experience.
I agree, I think option 1 would have the best user experience. I don't have a ton of JS experience (I try to avoid it as much as I can), but I figured there has to be a JS library out there that could help. Doing some searching I found Parsley. There was also a recent question on StackOverflow trying to solve a problem very similar to this one. The same user as that StackOverflow question also got some guidance when asked on Parsley's GitHub repository too.
In brief, it looks like we would need to use Parsley's Remote Validator to hit a new API endpoint that would return a list of all the device names that a user has. So, if I understand correctly, we shouldn't need much more than a small JS function which uses Parsley and a simple API endpoint. This project already has an API implemented for querying all the devices that a user has for example (see index
of /API/DevicesController.php
).
Thoughts?
That's awesome and look interesting! I can try to do it. But where do you wanna show validation error messages, below the input?
I think below the input makes sense. That seems to be the common way to use that library and their examples online often do that. It would also make it easier in the future if I needed more validation on some of those fields.
Are you still considering getting client-side validation working for this issue?
I’d like to do client-side validation. As you suggested in another PR, before starting, I’m better to delete my original fork and fork again. This PR probably will be ignored. But I’m kinda busy recently, so I don’t start yet.
The client-side validation can be also documented to the original issue, therefore anyone interested is welcome to do this.
Description
Disallow and show danger message when
Motivation and Context
Disallow duplicated device name for the same user #162
How Has This Been Tested?
Add a new test case for adding a device with an existing name.
Screenshots (if appropriate):
Types of changes
Checklist:
master
branch.