Home › Forums › Classic DFFS › Using buttons to "sign"
Tagged: sign
- This topic has 9 replies, 2 voices, and was last updated 5 years, 1 month ago by Therman.
-
AuthorPosts
-
-
October 5, 2019 at 02:05 #27237
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. -
October 6, 2019 at 11:39 #27242
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
-
October 6, 2019 at 14:25 #27244
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?
-
October 6, 2019 at 15:04 #27246
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
-
October 6, 2019 at 16:18 #27248
worked like a charm. thanks!
-
October 6, 2019 at 16:26 #27250
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”. -
October 7, 2019 at 21:05 #27264
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
-
October 8, 2019 at 16:39 #27279
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?
-
October 9, 2019 at 13:24 #27284
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
-
October 11, 2019 at 15:28 #27316
good deal. Thanks!
-
-
AuthorPosts
- You must be logged in to reply to this topic.