Using buttons to "sign"

Home Forums Classic DFFS Using buttons to "sign"

Tagged: 

Viewing 9 reply threads
  • Author
    Posts
    • #27237
      Therman
      Participant

        Is it possible for me to create a button that someone can press and then have that event capture the current user’s username in a field?
        In other words, I’m looking for a make-shift way for a user to digitally sign forms.

      • #27242
        Alexander Bautz
        Keymaster

          Just add a button in a HTML section and have it call this function:

          function signForm(){
            var user = spjs.utility.userInfo(_spPageContextInfo.userId);
            setFieldValue("NAME_OF_YOUR_FIELD", user.Title);
          }

          Alexander

        • #27244
          Therman
          Participant

            Thanks!

            When I put this in the HTML:
            `<button onclick=”signForm()”>Click to Sign</button>’

            And put this in the custom JS:
            ‘function signForm(){
            var user = spjs.utility.userInfo(_spPageContextInfo.userId);
            setFieldValue(“DirectorSignature”, user.Title);
            }’

            It works, but then the screen refreshes and I lose the signature. How do I stop the refresh?

          • #27246
            Alexander Bautz
            Keymaster

              Sorry, I should have specified it, but the <button> will cause a form submit and you must either return false, or better use an input like this:

              <input type="button" onclick="signForm()" value="Click to Sign" />

              Alexander

            • #27248
              Therman
              Participant

                worked like a charm. thanks!

              • #27250
                Therman
                Participant

                  Hey Alex, is it possible to maybe make the signature a username and date/time?
                  Maybe like this” “Last Name, First Name – 1 OCT 2019 – 11:26 AM”.

                • #27264
                  Alexander Bautz
                  Keymaster

                    You can do it like this:

                    function signForm(){
                      var user = spjs.utility.userInfo(_spPageContextInfo.userId);
                      setFieldValue("Title", user.Title + " " + new Date().toLocaleString(_spPageContextInfo.currentUICultureName));
                    }

                    Alexander

                  • #27279
                    Therman
                    Participant

                      Worked perfectly. Thanks.

                      I have four buttons for signature on my form.
                      Should I create 4 functions and apply to each button? Like this:

                      
                      
                      function signDir(){
                        var user = spjs.utility.userInfo(_spPageContextInfo.userId);
                        setFieldValue("DirectorSignature", user.Title + " " + new Date().toLocaleString(_spPageContextInfo.currentUICultureName));
                      }
                      
                      
                      function signG1(){
                        var user = spjs.utility.userInfo(_spPageContextInfo.userId);
                        setFieldValue("G1_Signature", user.Title + " " + new Date().toLocaleString(_spPageContextInfo.currentUICultureName));
                      }
                      
                      
                      function signG8(){
                        var user = spjs.utility.userInfo(_spPageContextInfo.userId);
                        setFieldValue("G8_Signature", user.Title + " " + new Date().toLocaleString(_spPageContextInfo.currentUICultureName));
                      }
                      
                      
                      function signCos(){
                        var user = spjs.utility.userInfo(_spPageContextInfo.userId);
                        setFieldValue("CoS_Signature", user.Title + " " + new Date().toLocaleString(_spPageContextInfo.currentUICultureName));
                      }

                      Or is their a best practice to write all of this?

                      • This reply was modified 5 years, 1 month ago by Therman.
                      • This reply was modified 5 years, 1 month ago by Therman.
                    • #27284
                      Alexander Bautz
                      Keymaster

                        This looks OK to me. You could of course use one function and pass a key to it as an argument, and then switch on the four different keys inside the function. It is easy to read and understand like you have written it now so just keep it like it is.

                        Alexander

                      • #27316
                        Therman
                        Participant

                          good deal. Thanks!

                      Viewing 9 reply threads
                      • You must be logged in to reply to this topic.