[openstreetmap/openstreetmap-website] Add some javascript to check dynamically if the username is already taken (PR #4402)

Tom Hughes notifications at github.com
Wed Dec 13 14:22:35 UTC 2023


@tomhughes commented on this pull request.



> @@ -223,4 +223,62 @@ $(document).ready(function () {
   $("#read_tou").on("click", function () {
     $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));
   });
+
+
+  const isTaken /* Record<string, string> */ = {}
+
+  function indicateInvalidDisplayName(isValid /* boolean | undefined*/) {
+    // isValid might also be 'undefined', hence we check explicitly for 'true' and 'false'
+    $("#user_display_name").toggleClass("is-valid", isValid === true)
+    $("#user_display_name").toggleClass("is-invalid", isValid === false)
+  }
+
+  function checkDisplayName(){
+    const displayName = $("#user_display_name").val()
+    if(displayName === ""){

We don't really want to be duplicating validations on the client as they will just get out of sync.

This is why it would probably better to have a specific backend method in the rails code that could be called with a proposed username and which would apply all the validations the user model will eventually apply.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4402#discussion_r1425427571
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4402/review/1779755826 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20231213/ddbbb1d7/attachment-0001.htm>


More information about the rails-dev mailing list