0

I have a form that needs an eSignature collected via mobile. I need it to be free with unlimited responses. I have a working jSignature HTML code for Google Sheets, but I cannot get it to work on mobile.

Ideally, I'd like to stick with Google, though I've been experimenting outside of it with things like Wix (doesn't do exactly what I need it to) or Android Studio (beyond my ability). My ability beyond that isn't great by any means so I'm not sure where to begin, though I have a suspicion it isn't about what I can do so much as what google sheets can do, as in, I've read a bit about how scripting doesn't work well on mobile.

HTML

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/willowsystems/jSignature/master/libs/jSignature.min.js"></script>
<body>
<form id="customerForm">
Please sign your name in the pad below: <br>
Full Name: <input type="text" name="username"><br>
Employee Number: <input type="employeenumber" name="useremployeenumber"><br><br>
Signature:
<div id="signature"></div><br>
<img id="rendered" src="" style="display:none">
<input type="button" value="Save" onclick="renderSignature();saveImage();"/>
</form>
</body>
<script>
  document.getElementById("signature").style.border = "1px solid black";
  
  $("#signature").jSignature({
    'background-color': 'transparent',
    'decor-color': 'transparent'
  });

  function renderSignature(){
    $("img#rendered").attr("src",$('#signature').jSignature('getData','default'));
  }

  function saveImage(e){ //This sends the image src to saveImages function
    var bytes = document.getElementById('rendered').src;
    console.log(bytes);
    var sign = {
      username: document.getElementsByName('username')[0].value,
      useremployeenumber: document.getElementsByName('useremployeenumber')[0].value
    };
    google.script.run.saveImage(bytes, sign);
    return
  } 
  window.onload=function(){
  google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.saveImage(bytes, sign);
}

</script>



</html>

CODE.GS

function showDialog() {
  var html = HtmlService.createHtmlOutputFromFile('jSignature')
    .setWidth(400)
    .setHeight(300);
   SpreadsheetApp.getUi()
  .showModalDialog(html, 'Your Signature is Required');
}

function doGet() {
  return HtmlService
      .createTemplateFromFile('jSignature')
      .evaluate();
}


function saveImage(bytes, sign){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('my page name');
  var dateObj = Date.now();
  var bytes = bytes.split(",")
  var blob = Utilities.newBlob(Utilities.base64Decode(bytes[1]), 'image/png');
  var fileName = blob.setName("Signature "+dateObj).getName();
  var sigFolder = DriveApp.getFolderById("my folder id");
  var url = sigFolder.createFile(blob).getId();
  Logger.log(url)
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Register');
  var name = sign.username;
  var employeenumber = sign.useremployeenumber;
  var signature = ss.insertImage(blob,4,ss.getLastRow()+1);
  signature.setWidth(500);
  signature.setHeight(20);
  signature
  var imageCell = ss.getRange(ss.getLastRow()+1, 1, 1, 3).setValues([[Date(), name,employeenumber]]);
}
    

What I've been thinking about is having the user open the form responses google sheet first, to a page with a link to the form. They would follow that link, fill out the form then be taken back to the google sheets form where an onFormSubmit trigger would bring up the jSignature pad. They would sign and all the information would be collected on one line in the form responses.

How do I make jSignature work for Google Sheets mobile? Is it even possible?

Marios
  • 26,333
  • 8
  • 32
  • 52
NMALM
  • 378
  • 2
  • 19
  • Web app should be accessible from mobile – TheMaster Sep 05 '19 at 14:42
  • That did it! I guess that's why they call you TheMaster. Bad jokes aside, thank you. – NMALM Sep 05 '19 at 16:40
  • @NMALM did you manage to make it work in ipad and mobile, for me the issues is the pad works perfectly in desktop but for ipad and mobile the pop up doesnt open and also it gives me error ""Script signaturePopup experienced an error" how can i make it work it work for ipad and mobile – Naved Madabhavi May 03 '20 at 22:10

0 Answers0