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">×</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();
};