FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Specify default value for form field?

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    4
    6
    8.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      elliotdickison
      last edited by

      Is there any way to specify the default value for a form field, either at the field level or the form level? I can't seem to find documentation regarding this, but it would be a helpful feature for advanced registration forms.

      mark.robustelliM 1 Reply Last reply Reply Quote 0
      • mark.robustelliM
        mark.robustelli @elliotdickison
        last edited by

        @elliotdickison I don't know of a way to get the default value for a form, but you may be able to use javascript to populate the values on the form.

        D 1 Reply Last reply Reply Quote 0
        • D
          daenerystargaryen56 @mark.robustelli
          last edited by

          I think you can try using custom JavaScript code. To set a default value for a form field, you can utilize JavaScript to manipulate the field's value after the form is loaded. Here's an example of how you can accomplish this:

          Add an HTML class or ID to the form field you want to set a default value for. For example, let's say the class is "default-value-field".

          In your FusionAuth theme or custom HTML file, add a script tag that runs after the form has loaded:

          html
          <script>
              document.addEventListener("DOMContentLoaded", function() {
                  // Find the form field by class or ID
                  var defaultField = document.querySelector(".default-value-field");
                  
                  // Set the default value
                  defaultField.value = "Your default value";
              });
          </script>
          

          This script listens for the "DOMContentLoaded" event, which occurs when the page is fully loaded. It then selects the form field using the class or ID you specified and sets its value to the desired default value.

          1 Reply Last reply Reply Quote 0
          • E
            elliotdickison
            last edited by

            Thanks for the tips! I do love that customizing FusionAuth's theme templates allows you to accomplish pretty much anything. For our use-case - lots of custom forms for lots of tenants - I would prefer to be able to use the advanced registration form feature instead of polluting theme files with JS snippets. At that point I think I might as well hardcode the HTML for the fields instead of adding JS.

            V 1 Reply Last reply Reply Quote 2
            • V
              vatsal @elliotdickison
              last edited by

              @elliotdickison Hi, Did you find a way to provide default values to a form field? We're also not looking forward to add HTML for each of the theme. Thanks in advance.

              E 1 Reply Last reply Reply Quote 0
              • E
                elliotdickison @vatsal
                last edited by

                @vatsal We did not

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post