Trouble initializing jSignature on multiple pages with jQuery Mobile

My jquery mobile app is displaying 3 jsignature divs correctly on certain pages, but not on others. The problem arises when the div shows up with a squished height and is unresponsive to touch:

Currently, I'm loading these divs using a document ready function at the bottom of the page, which seems fine:

<div id="info" data-role="page" data-theme="c">
<div data-role="header" data-theme="b>
<h1>NewF</h1>
</div>
<div data-role="content">
<form datapersist="garlic" encoding="multipart/form-data" encType="multipart/form-data">
<input type="text" placeholder="Your Name" name="_fid_14" id="_fid_14" />
</form>
</div></div>

... (additional HTML code for signature pages)

But when I change the structure so each signature loads on its own page, they lose size and functionality. Here's an example:

(modified HTML code) 

... (new structure where signatures are loaded individually on different pages)

I've attempted to use pageinit on the signature pages as well, but encountered the same issue:

(tried using pageinit on signature pages)

The signatures work correctly on one sub-page but not on another. This discrepancy has left me puzzled. Any insights or suggestions would be greatly appreciated!

  • Update: Upon directly refreshing /index.html#fcmsignature, the signature displays correctly. Therefore, the problem appears to be related to the initialization of the signatures. I have tried pageinit without success and also experimented with data-transition="none" on buttons, but no improvement.

Answer №1

Consider using the following syntax:

$('#fcmsignature, #gcsignature, #inspsignature').live('pageshow',function(e,data){
    $('#fcmsig').jSignature({'UndoButton':false,color:"#000000",lineWidth:1});
    $('#gcsig').jSignature({'UndoButton':false,color:"#000000",lineWidth:1});
    $('#inspsig').jSignature({'UndoButton':false,color:"#000000",lineWidth:1});
});

This code ensures that jQuery and jQuery mobile are loaded, and it will only execute when pages fcmsignature, #gcsignature, #inspsignature are about to be displayed. Since each page has one signature, you should use it like this:

$('#fcmsignature').live('pageshow',function(e,data){
        if($('#fcmsig').find('.jSignature').length == 0){
            $('#fcmsig').jSignature({'UndoButton':false,color:"#000000",lineWidth:1});
        }
});

$('#gcsignature').live('pageshow',function(e,data){
        if($('#gcsig').find('.jSignature').length == 0){
            $('#gcsig').jSignature({'UndoButton':false,color:"#000000",lineWidth:1});
        }
});

$('#inspsignature').live('pageshow',function(e,data){
        if($('#inspsig').find('.jSignature').length == 0){
            $('#inspsig').jSignature({'UndoButton':false,color:"#000000",lineWidth:1});
        }
});

jQM was not designed to work with $(document).ready( function(){. Read my other article to learn more:

Answer №2

If you're facing a similar problem, I found success by binding jSignature to the "pageshow" event.

    $("#signpage").on("pageshow",function(e,data){
      if($("#signature").find(".jSignature").length == 0){
                    $("#signature").jSignature();
      }
    });

Answer №3

For those seeking to update their code, it's important to note that the jQuery live() method is no longer recommended starting from version 1.7 of jQuery, and has been completely removed as of version 1.9. A viable alternative would be to utilize the jQuery Mobile "pagecontainershow" event handler and assess which page is currently active before executing the necessary logic outlined in previous responses:

$(document).on("pagecontainershow", function(evt, ui){
    var pageID = $('body').pagecontainer('getActivePage').prop('id');

    if(pageID == 'signaturePage'){
        if($("#signatureDiv").find(".jSignature").length == 0){
            $("#signatureDiv").jSignature();
        }
    }
}

This updated approach remains effective with jQuery versions 1.11.3 and jQuery Mobile 1.4.5.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Are there distinctions between initializing a JavaScript variable with [] as opposed to {}?

Throughout my coding journey, I've always used: var j= {}; j['field'] = value; It turns out the following also works: var j= []; j['field'] = value; Is there any difference between the two? Edit: Apologies for using the wrong ...

Objects hidden in the darkness, utilizing the traditional MeshPhongMaterial

Currently struggling with my shadows issue. Here is a snapshot of the problem I am encountering: https://i.sstatic.net/odnuE.png https://i.sstatic.net/RZitM.png The presence of those lines puzzles me, as the scene should be evenly illuminated! The shado ...

I am unable to submit the form to the server

I'm experiencing an issue with my login form. I've tried submitting it using jQuery, but it's not working as expected. I've searched online for solutions, but they all seem too complex. Here is the code I'm working with: <form ...

Why is my webpage attempting to refresh every time I send an AJAX request?

I have been struggling to send a form using AJAX, but no matter how many times I use e.preventDefault(), the page still tries to reload. Here is my HTML: <form action="/user/changeProfileData" id="edit-profile_form" method="post"> <ul class=& ...

Developing a universally accessible variable for utilization in various functions

I'm having trouble understanding why 'currentPos.LatLng' is undefined when trying to access it outside the function even though it's part of an object. I want to be able to retrieve the current position values to use them in another fun ...

An easy guide to rerouting a 404 path back to the Home page using Vue Router in Vue.js 3

Hello amazing community! I'm facing a small challenge with Vue.js 3. I am having trouble setting up a redirect for any unknown route to "/" in the router. const routes = [ { path: "/", name: "Home", component: Home, }, { path: "* ...

Locate the closest pals near my present whereabouts

Is it possible to find my friends by obtaining their location from their mobile phones when they are near me? I have a code snippet below with the variable cities where I can input the numbers of my friends. Can I achieve this or do I need to make some m ...

Unable to decompress using gunzip and serverless-http due to incorrect header check error, yet functions properly with a standard Node.js Express server

Currently, I am tackling an issue with the serverless framework and serverless-http library while attempting to decompress a binary request. The peculiar thing is that the exact code segment functions properly in a typical expressjs server but encounters i ...

Attempting to develop a worldwide npm package. Upon running my script, I encounter the message "The designated path cannot be found."

I have been working on converting my npm module into a global command. You can find the code at this link. However, when I try to run $ seed, an error stating "The system cannot find the path specified" is displayed, indicating that it recognizes it as a ...

Preserve the iframe src value in the dropdown menu even after the page is refreshed

I am trying to figure out how to prevent the iframe src from changing when I refresh the page, unless the user manually changes it using the dropdown menu with JavaScript. Can someone help me with this? <div class="row"> <div class="span9"> ...

What methods can be used to initiate form error handling in React/Javascript?

I am currently utilizing Material-UI Google Autocomplete, which can be found at https://material-ui.com/components/autocomplete/#google-maps-place, in order to prompt users to provide their address. https://i.stack.imgur.com/nsBpE.png My primary inquiry ...

What is the process for adjusting the color of a div?

Is there a way to adjust the background color of a div when hovering over another div in HTML? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.or ...

Bidirectional data binding between an Angular component and its parent controller

I am currently facing an issue with an Angular component (vendor-filters) where I am trying to pass data to and from a parent controller. The goal is to create a filter based on mainInfo and update the parent controller with the filtered data. However, I a ...

The Microsoft Booking feature is not being shown in the iframe

https://i.sstatic.net/QYNGI.png Instead of the booking website, this is what is being displayed. Below is the code snippet: index.js import React from 'react' const Appointment = () => { return ( <iframe src='https://outlook ...

Adaptive selection choices determined by prior selections

After some reflection, I realized that my initial approach to a previous question was incorrect. I currently have an array of data that can be converted to JSON data if necessary. The data structure is as follows: array:4 [▼ "data" => array:2 [▼ ...

When attempting to use the jsonify method on a variable within an html file, the output is not displayed

Is it possible to store "jsonify" in a variable? I find the pure json format of "return jsonify(data)" unappealing, so I am looking for a way to enhance it using an HTML template with proper indentation. Here's the python code I have: from flask impo ...

Deactivate a button based on a comparison condition

How can I prevent a button from being clickable when a specific condition is met? I attempted to do it this way, but it seems to be ineffective: <button type="text" disabled="{{candidature.statusCandidature.libelle == 'En cours' }}" >edit ...

Guidance on AngularJS route parameter passing in view URLs

How can I successfully pass the parameter id in the URL using angularJS? I have tried the following in my home.config: home.config(["$routeProvider",function ($routeProvider) { $routeProvider .when("/profile",{ templateUrl : "views/home/profil ...

Learn the steps to dynamically adjust the size of a pop-up window in Sencha based on the content that is

This is the designated container where I plan to display text. The code resides within a modal (pop-up) and it's important for the pop-up to adjust its height based on the loaded text. Ext.define('Base.view.Notes', { extend: 'Ext.Co ...

Limited functionality: MVC 5, Ajax, and Jquery script runs once

<script> $(function () { var ajaxSubmit = function () { var $form = $(this); var settings = { data: $(this).serialize(), url: $(this).attr("action"), type: $(this).attr("method") }; ...