• Ginger
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Dear Friends:

I am trying to invoke an apex method from javascript but some reason it's not. I must be doing bluder mistake which I could not figure out so I woule like request the member to review the below given code and let me know what am I doing wrong.

 

Thank you very much inadvance for your time.

 

VF Page:

<apex:page showheader="false" controller="CaptureSignature">
    <head>
      <link rel="stylesheet" href="{!URLFOR($Resource.jsSignature,'build/jquery.signaturepad.css')}" />
      <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
      <script src="{!URLFOR($Resource.jsSignature, 'build/jquery.signaturepad.min.js')}"></script>
      <script src="{!URLFOR($Resource.jsSignature, 'build/json2.min.js')}"></script>
    </head>

   <body>
        <form method="post" class="sigPad" >
           <apex:form >
             <apex:actionFunction action="{!capSig}" name="capSignature"/>
                  <ul class="sigNav">
                  <li class="drawIt"><a href="#draw-it">Draw your signature</a></li>
                  <li class="clearButton"><a href="#clear">Clear</a></li>
                  </ul>
                      <div class="sig sigWrapper">
                      <canvas class="pad" width="198" height="55"></canvas>
                      <input type="hidden" name="output" class="output"/>
                      </div>
                      <button name="submit" onClick="saveImg(output);">Submit</button>
            </apex:form>
        </form>
     
        <script>
            function saveImg()
            {
                var api = $('.sigPad').signaturePad();
                var sigPad;
                var sig = '';
                if(api.validateForm())
                {
                    sig = api.getSignatureImage();
                     alert('sig = ' + sig);
                  //  document.getElementById('submit').innerHTML = sig;
                  }
                capSignature();
               return sig;
              
            }
            $(document).ready(function() {
              sigPad = $('.sigPad').signaturePad({drawOnly:true});
            });
        </script>
    </body>
</apex:page>

 

Controller:

public class CaptureSignature {
    
    public string SignatureImage{get; set;}
    
    public PageReference capSig() {
            System.debug('**** SignatureImage:' + SignatureImage);
           //create sample signature attachment image
            Attachment newAttachment = new Attachment();
            newAttachment.ParentId = 'TestSigCap';
            String imageBody = SignatureImage.replaceAll('data:image/png;base64,', '');
            newAttachment.body = Encodingutil.base64Decode(imageBody);
            newAttachment.name = 'sampleSignature.png';
            insert newAttachment;

     
    return null;
    }

}

  • October 03, 2012
  • Like
  • 0

Naive question, how to update a custom master object  with distinct child counts on nightly basis?

Any input is highly appreciated.

 

Thanks

Dear Friends:

I am trying to invoke an apex method from javascript but some reason it's not. I must be doing bluder mistake which I could not figure out so I woule like request the member to review the below given code and let me know what am I doing wrong.

 

Thank you very much inadvance for your time.

 

VF Page:

<apex:page showheader="false" controller="CaptureSignature">
    <head>
      <link rel="stylesheet" href="{!URLFOR($Resource.jsSignature,'build/jquery.signaturepad.css')}" />
      <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
      <script src="{!URLFOR($Resource.jsSignature, 'build/jquery.signaturepad.min.js')}"></script>
      <script src="{!URLFOR($Resource.jsSignature, 'build/json2.min.js')}"></script>
    </head>

   <body>
        <form method="post" class="sigPad" >
           <apex:form >
             <apex:actionFunction action="{!capSig}" name="capSignature"/>
                  <ul class="sigNav">
                  <li class="drawIt"><a href="#draw-it">Draw your signature</a></li>
                  <li class="clearButton"><a href="#clear">Clear</a></li>
                  </ul>
                      <div class="sig sigWrapper">
                      <canvas class="pad" width="198" height="55"></canvas>
                      <input type="hidden" name="output" class="output"/>
                      </div>
                      <button name="submit" onClick="saveImg(output);">Submit</button>
            </apex:form>
        </form>
     
        <script>
            function saveImg()
            {
                var api = $('.sigPad').signaturePad();
                var sigPad;
                var sig = '';
                if(api.validateForm())
                {
                    sig = api.getSignatureImage();
                     alert('sig = ' + sig);
                  //  document.getElementById('submit').innerHTML = sig;
                  }
                capSignature();
               return sig;
              
            }
            $(document).ready(function() {
              sigPad = $('.sigPad').signaturePad({drawOnly:true});
            });
        </script>
    </body>
</apex:page>

 

Controller:

public class CaptureSignature {
    
    public string SignatureImage{get; set;}
    
    public PageReference capSig() {
            System.debug('**** SignatureImage:' + SignatureImage);
           //create sample signature attachment image
            Attachment newAttachment = new Attachment();
            newAttachment.ParentId = 'TestSigCap';
            String imageBody = SignatureImage.replaceAll('data:image/png;base64,', '');
            newAttachment.body = Encodingutil.base64Decode(imageBody);
            newAttachment.name = 'sampleSignature.png';
            insert newAttachment;

     
    return null;
    }

}

  • October 03, 2012
  • Like
  • 0