Exploring the intricacies of detecting changes on a signature pad within an Angular

Currently, I have integrated a signature_pad and an email input field in my web application. Both fields need to be filled out for the next step to become enabled (

x-ng-disabled="!checkSignatureAndEmail()"
).

The email field has a ng-model, ensuring immediate detection of any changes. However, the signature pad relies on plain JavaScript. This poses a challenge where entering the email first followed by signing on the pad doesn't enable the button.

I'm curious if there's a way to set up a listener or some mechanism to address this issue? If yes, how would I go about doing it?

<div class="container">
    <div class="modal fade" id="signatureDialog" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Confirm Order</h4>
                </div>
                <div class="modal-body">
                    <p>By providing your signature, you confirm...</p>
                    <input type="text" class="form-control" x-ng-model="email">
                    <br>
                    <canvas id="signature-pad" width="700" height="150" style="border:1px solid #B0B0B0; border-radius: 4px;" x-ng-init="initSignaturePad()"></canvas>
                    <br>
                    <button type="button" class="btn btn-default" x-ng-click="signaturePad.clear()">Clear</button>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" x-ng-disabled="!checkSignatureAndEmail()" x-ng-click="saveOrder(orderInput)" data-dismiss="modal">Confirm</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                </div>
            </div>
        </div>
    </div>
</div>

In the controller:

Initialize SignaturePad:

$scope.initSignaturePad = function() {
    $scope.signaturePad = new SignaturePad(document.getElementById('signature-pad'), {
          minWidth: 1.2,
          maxWidth: 3,
          backgroundColor: 'rgba(250, 250, 250, 1)',
          penColor: 'rgb(0, 0, 100)'
    });
}

Validation logic:

$scope.checkSignatureAndEmail = function() {
    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test($scope.email) && !$scope.signaturePad.isEmpty();
};

Answer №1

Give this a shot:

To make changes in your HTML, replace x-ng-init with x-ng-mouseup event at canvas:

<canvas id="signature-pad" x-ng-mouseup="initSignaturePad()"></canvas>

Update your controller accordingly:

  $scope.emptyCanvas = true;

  $scope.$watch('emptyCanvas', function() {
      $scope.checkSignatureAndEmail();
  });

  $scope.checkSignatureAndEmail = function() {
      var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      return re.test($scope.email) && !$scope.emptyCanvas;
  };

  $scope.initSignaturePad = function() {    
        $scope.emptyCanvas = $scope.signaturePad.isEmpty();
    };

This solution works for me, but it may not be exactly what you're looking for with x-ng-mouseup.

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

If a box in the grid contains a certain class, then JavaScript should be

I've set up a grid featuring a player, represented by a yellow box, along with obstacles denoted by black boxes marked with the .ob class. I want to prevent the player from moving into these obstacle squares when the 'UP' button is clicked. ...

developing a cheat prevention system for an internet-based multiplayer game

I am facing an issue with my website that includes a simple game and a basic scoreboard feature using express. Whenever a player dies in the game, their score is sent to the server via a post request and added to the leaderboard. The problem I'm encou ...

Get the docx file as a blob

When sending a docx file from the backend using Express, the code looks like this: module.exports = (req, res) => { res.status(200).sendFile(__dirname+"/output.docx") } To download and save the file as a blob in Angular, the following code snippet i ...

Creating intricate structures using TypeScript recursively

When working with Angular and TypeScript, we have the power of generics and Compile-goodness to ensure type-safety. However, when using services like HTTP-Service, we only receive parsed JSON instead of specific objects. Below are some generic methods that ...

Performing AJAX requests within AJAX requests without specifying a callback function for success

Upon reviewing this discussion jQuery Ajax Request inside Ajax Request Hello everyone, I'm in need of some clarification on a particular scenario. I recently took over the code from a former member of my development team and noticed that they have ma ...

Exploring PHP Directories

I am currently working on developing a small PHP Filebrowser This code snippet displays my files when the page loads. $dir = './files'; $directories = array(); $files_list = array(); $files = scandir($dir); foreach($files as $file){ if(($fi ...

Numerous toggles available for the mobile version

Hey there, I need some help! I have a footer navigation on my desktop website with 3 Ul elements. I want to turn each Ul into a toggle for the mobile version. Can anyone assist me with this? Thanks in advance! <footer class="footer"> <d ...

Function that yields promise result

I need help figuring out how to make this recursive function return a promise value. I've attempted various approaches, but they all resulted in the search variable ending up as undefined. public search(message: Message) { let searchResult: strin ...

Error message: Issue with TypeScript and cleave.js - 'rawValue' property is not found on type 'EventTarget & HTMLInputElement'

I am encountering an error with the onChange event while implementing cleave in typescript. TypeScript is throwing an error indicating that 'rawValue' is not present in event.target. Here is my code: import React, { useCallback, useState, useEff ...

Eliminate placeholder text when the tab key is pressed

I'm currently facing an issue with a textarea that has a placeholder and the Tab key functionality in Internet Explorer. I've included placeholder.js to make it work, but when I repeatedly press the tab key and focus on the textarea, the placehol ...

When the only source is available, the image undergoes a transformation

Is there a way to dynamically adjust the height of an image using JQuery or JavaScript, but only when the image source is not empty? Currently, I have an image element with a fixed height, and even when there is no source for it, Chrome still reserves sp ...

Tips for redirecting a page in React by forcing a route

Attempting to implement the guidance from this Stack Overflow solution on how to "go back home" after closing a Modal... import React, { Suspense, useState } from 'react'; import { BrowserRouter, Route, Switch, useHistory } from "react-route ...

Creating evenly spaced PHP-generated divs without utilizing flexbox

My goal is to display images randomly from my image file using PHP, which is working fine. However, I am facing an issue with spacing the images evenly to fill the width of my site. This is how it currently appears: https://i.stack.imgur.com/AzKTK.png I ...

Utilizing the jexcel plugin to seamlessly integrate arrays for a personalized subtitle editing experience

Could you please assist me in understanding how to utilize the jexcel plugin for pushing arrays? To achieve the push functionality, I would like it to behave similarly to arrays containing 6 different colors as outlined below: Subtitles = orange, Caption ...

How should elements be properly inserted into injected HTML code?

We are currently phasing out our custom forms in React on the website, and transitioning to Microsoft Dynamics 365 generated forms. These new forms are injected through a React placeholder component created by a script that loads the js bundle and inserts ...

"Guidelines for implementing a post-login redirection to the homepage in React with the latest version of react-router (v

I am facing an issue where I am unable to redirect to the Home Page when I click the "Login" button during my React studies. Despite trying all possible methods for redirects, none of them seem to work. The function that is executed when I click the "logi ...

The outcomes of my JavaScript code are not aligning with my expectations

I've been experimenting with printing objects from an API using JSON and AJAX, and I noticed that the console.log works perfectly to display the output. However, I'm having a bit of trouble with my generateCreatureDiv function as it doesn't ...

Instructions for converting SCSS to CSS and storing the CSS code as a string in a variable

I am currently developing a Single Page Application (SPA) using Vue (specifically Quasar), and I have the following requirements: Load the contents of a CSS file into a JavaScript variable or Vue data property dynamically The CSS file should be generated ...

Angular JS Changing Values in a Dynamic List

Creating Dynamic HTML with Angular Directives I'm working on code that generates HTML dynamically and includes Angular directives. Since these directives are late-bound, I need to ensure they execute and generate their respective template contents. I ...

Generate a separate div in an HTML file for each item listed in a JSON document

I have a JSON file structured like this: { "text": "HelloWorld", "id&quo;t: "1", }, { "text": "HelloMoon", "id": "2", } Now, I want to generate a <div> in my HTML for ...