Combining Ng-model with iOS credit card scanning functionality offers a seamless and

Dealing with Ng-model and iOS credit card scanning

In my credit card form, each field is structured like this:

<input type=“text” ng-model = “cc.number”, ng-class = validClass('cc.number’)>

The function validClass returns either valid or invalid, providing real-time validation feedback. Everything functions properly - any incorrect input highlights in red as the user types.

Upon hitting 'submit', the code processes the values of cc.number, cc.securityCode, cc.month, and cc.year for credit card operations.

An issue arises when utilizing iOS's credit card scanner. This feature allows users to use their phone camera to scan a physical credit card and auto-populate the fields with the scanned information. However, Safari on iOS doesn't seem to trigger an update to the ng-model data, leading to discrepancies in validation handling and submitted values.

Troubleshooting this problem is complicated because the scanning feature isn't supported in the iOS simulator or when accessing a local network (e.g., a laptop). It appears to only work on secure https sites, making it challenging to diagnose.

TLDR: iOS Safari's credit card scanning feature fails to update ng-model variables accurately. Any suggestions for resolving or bypassing this issue?

Answer №1

To work around this issue, consider updating the model after the user has submitted the form. Ensure that both the form and the cc-number input are named so that they can be referenced from the scope.

<form name='creditCardForm'>
  <input name='cardNumber' ...>

Within your submit handler...

var cardNumber = $('[name="cardNumber"]').val()
$scope.creditCardForm.cardNumber.$setViewValue(cardNumber);

This action will update the model and set the validity, allowing you to prevent submission if it is invalid.

if ($scope.creditCardForm.cardNumber.$invalid) {
  // Cancel submission...

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

What measures does Redux take to ensure race conditions do not occur?

Recently, I delved into Redux and grasped the concept very well. However, there is one particular line in the official documentation that puzzled me: Because all changes are centralized and happen one by one in a strict order, there are no subtle race ...

Disabling the ng-click event in a confirmation popup button: a step-by-step guide

Is there a way to prevent ng-click event from triggering in a confirmation popup button? 1[Screen-Shot] ...

Combining Various Advertising Networks in a Mobile App for iOS and Android

I am the creator of a mobile application (but not the developer) and am currently collaborating with a developer to monetize my iOS and Android apps. According to my developer, we are not allowed to incorporate more than one ad network into an app. My sp ...

JavaScript and HTML with Node.js

Exploring the world of HTML, running smoothly with a static IP address 192.168.56.152 using apache on the host computer. <!DOCTYPE html> <html > <head> <title>OnlinePage</title> <meta charset="utf-8"& ...

Can anyone help me get my carousel to work properly?

I am facing a carousel problem in my personal exercise project. I have gathered HTML, CSS, and JavaScript from the internet and am attempting to integrate them all together. //Sidebar script start $(document).ready(function () { var trigger = $(&apo ...

Collaborating with a container element

Here is the scenario I'm facing: I have a viewController with three buttons at the top and a containerview below them. The goal is to switch the content of the container view when one of the buttons is clicked. This is what I have set up in the story ...

Loading Vue bootstrap b-form-select initially triggers Vuelidate's $anyDirty to become true

My current issue arises from the input event triggering when I initially assign a value to the v-model. This data is fetched via an API, causing the form to be marked as dirty due to the change. However, this poses a problem in another component where the ...

The functionality of scope.$observe is unavailable within an AngularJS Directive

Consider the snippet below: appDirectives.directive('drFadeHighlight', ['$animate', '$timeout', function ($animate, $timeout) { return { scope: { isWatchObject: '=' }, restric ...

Transmit a data point from JavaScript to PHP

I am looking to transfer the address value to a different PHP page <script> var userAddress = place.formatted_address; document.getElementById('af').innerHTML = userAddress; </script> ...

What is the best way to retrieve a specific value from an array of objects based on a condition?

I need some assistance with writing a function. Can you help me out? Let's say I have an array of objects: const movieGen = [ { id: 28, name: "Action" }, { id: 12, name: "Adventure" }, { id: 16, name: "Animation" }, ...

Encountering an issue with NPM while attempting to install Parcel

After trying multiple solutions from various online sources, I am still unable to resolve the issue. Any advice or recommendations would be highly appreciated! npm ERR! code 1 npm ERR! path C:\Users\Tarun\Desktop\NamasteReact\node_ ...

Loop through a MongoDB collection to retrieve documents, then perform API calls to add additional keys to the data before sending it

I am currently utilizing the following code snippet to retrieve data from a collection: Marketing.find({ shopId: req.params.shopId, locationId: req.params.locationId, }).exec(function (err, campaigns) { if (err) { return next(err); } else if (!campaigns) ...

Is there a way to dynamically change the title of a tab when new content is added to a minimized page?

Is anyone familiar with how websites like Facebook and Buzzfeed update their tab titles when there are multiple tabs open? I have noticed that sometimes they add a "(1)" or "(2)" to indicate changes on the page. Do they use JavaScript to achieve this eff ...

Keep a vigilant eye on the peak utilization of memory within the Node.js process

I am in search of a way to effectively monitor the maximum memory usage in a Node.js process, regardless of whether there are memory leaks or not. The processes in question include both real applications and synthetic tests. My expectation is that it sho ...

Using flags to translate text on Google should not result in being redirected to another website

I have integrated Google's language picker with country flags into my WordPress template using the code below: <!-- Add English to Chinese (Simplified) BETA --> <a target="_blank" rel="nofollow" onclick="window.open('http://www.google. ...

Troubleshooting jQuery and Mootools compatibility problem in Internet Explorer 8

I am currently working on a webpage that is using both Mootools 1.4 and jQuery 1.5.1 at the same time. I understand that this setup is not ideal, but for various reasons, I have no choice in the matter. Most browsers display the page without any issues, ho ...

Sending Data Back to Main Function Using a Callback

When I try to call the emailExists() function, it should ideally return true or false. However, instead of that expected behavior, I am encountering this error: TypeError: cb is not a function Since asynchronous operations and callbacks are relatively ne ...

Jquery's .text() and .html() methods seem to be malfunctioning

Utilizing a jQuery function: $("#btn1").click(function(){ $("p").text("") } Each time the button is clicked, the .text() field fails to load. When I modify the value of .text to a shorter string, it functions correctly. ...

Find the value of the closest HTML thead element upon clicking a td cell

I am having an issue with my HTML table layout, here is the code: jQuery(document).ready(function($) { $('#reservationtable tbody tr td').on('click', function () { var reservationtime = $( this ).siblings('th&a ...

confirmation message upon completing a form submission

<script> var remainingCredit = document.getElementById("cor_credit"); var remaining = document.getElementById("remain_credit"); function validateForm() { if (remaining.value < remainingCredit.value) { return conf ...