Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add a name validation for dots at registration
Sebastian Martinez committed 3 years ago
commit c5eddde23f733ad90bf3dd2f94dad2e722a7f4d6
parent 93b7b6b2a083ac6479e2cb21dbfc6fc50fd6e41d
1 file changed +30 -7
modified src/base/registrations/Index.svelte
@@ -11,7 +11,25 @@
  function register() {
    navigate(`/registrations/${label}/form`);
  }
+

+
  function validate(input: string): string[] {
+
    const errors: string[] = [];
+

+
    if (input && input.includes(".")) {
+
      errors.push("Please do not use dots as separators.");
+
    }
+
    if (input && input.length < 2) {
+
      errors.push("Please enter a minimum of 2 characters.");
+
    }
+
    if (input && input.length > 128) {
+
      errors.push("Please enter a maximum of 128 characters.");
+
    }
+

+
    return errors;
+
  }
+

  $: label = input.trim();
+
  $: errors = validate(label);
</script>

<style>
@@ -65,16 +83,21 @@
          placeholder=""
          root={config.registrar.domain}
        />
-
        {#if label && label.length < 2}
-
          <span class="input-info">Please enter a minimum of 2 characters.</span>
-
        {:else if label && label.length > 128}
-
          <span class="input-info">Please enter a maximum of 128 characters.</span>
+
        {#if errors}
+
          <div class="input-info">
+
            {#each errors as error}
+
              <div>{error}</div>
+
            {/each}
+
          </div>
        {/if}
      </span>

-
      <button disabled={!label || label.length < 2 || label.length > 128} class="primary register regular" on:click={register}>
-
        Check
-
      </button>
+
        <button
+
          disabled={!label || errors.length !== 0}
+
          class="primary register regular"
+
          on:click={register}>
+
            Check
+
        </button>
    </div>
  </div>
</main>