AngularJS 1.5 - Form submission with missing mandatory fields triggers on iOS

I've been working on a Cordova app using AngularJS (1.5.11) and I've run into a strange bug on iOS that doesn't occur on Android (despite using the same code).

I've stripped down unnecessary elements from the form to isolate the issue, but the bug persists.

Below is the simplified form:

<form method="post" ng-submit="$ctrl.login()">
    <input type="email" name="username" value="" required ng-model="$ctrl.username">
    <input type="password" name="password" value="" required ng-model="$ctrl.password">
    <button type="submit">Submit</button>
</form>

The problem I'm facing is that the form submits even when it's invalid. It's a basic login form with fields for username, password, and a submit button.

Strangely, this issue affects every form in my app.

Am I overlooking something here? Any help would be greatly appreciated :)

Answer â„–1

You have three choices available:

Option 1: Inactivate the submit button when the form is not valid:

<form name="needNameForm" method="post" ng-submit="$ctrl.login()">
...
<button type="submit" ng-disabled="needNameForm.$invalid">Submit</button>
</form>

Option 2: Disregard the submission if the form is invalid:

<form name="needNameForm" method="post" 
ng-submit="needNameForm.$valid && $ctrl.login()">
...
</form>

Option 3: Validate in your submit method:

<form name="needNameForm" method="post" 
ng-submit="$ctrl.login(needNameForm)">
...
</form>
<!-- For testing purposes, you can display this line below -->
<pre>{{needNameForm | json}}</pre>

In your controller:

angular.controller('name', function(){
var vm = this;
vm.login = function(formController){
  if(formController.$valid){
   performActions();
  }
 }
}

By choosing the third option, you gain more control over individual input validation within the form. The formController object provides comprehensive information for each input. Don't forget to assign names to your inputs for complete data access. Refer to this documentation for more details.

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

Can you explain the distinction between document.body.ononline and navigator.onLine?

Can you explain the distinction between document.body.ononline and navigator.onLine? Do they utilize the same JavaScript API for checking network connectivity status (online/offline)? I have searched on Google but couldn't find a definitive answer. If ...

Unable to access a frame inside an iframe and frameset using JavaScript when both domains are identical

I am attempting to use JavaScript to access an HTML element within a nested frame in an iframe and frameset. The structure of the HTML is as follows: <iframe id="central_iframe" name="central_iframe" (...)> <frameset cols="185, *" border="0" ...

What could be causing the function to not work properly within the React component?

Having trouble with a React component utilizing speech recognition for converting speech to text. Initialized the recognition functions within the component but encountering errors. Need assistance in troubleshooting this issue. const speechRecognition = w ...

Is it possible to assign a value to a React hook within a promise?

After retrieving data from a promise, I need to store it in a React hook. However, this process is causing infinite requests and continuous re-rendering of the page. Additionally, I only want to fill specific data. const [rows, setRows] = useState([]); ...

angular directive losing track of child content

Within my Angular directive, I have created a custom tag <my-tag> and replaced it with a simple <div> in the definition code: .directive('myTag',function(){ return { restrict: 'E', template: '<div>conte ...

Connections between Ember and mongo databases

Currently, I am exploring the most effective approach for my Ember App. I am dealing with two separate models: events and bookings. In my database, I have structured them in a completely independent manner. Schemas: Events: attributes: date : ...

Ways to have a div show up and stay in place as you scroll down?

How can I make the div "full" sticky after scrolling down 200px, and revert to display none when scrolling back up? Is there a way to accomplish this using JavaScript? In the code snippet below, you will find three divs: header, header2, and header3. The ...

Tips on implementing multiple routing in AngularJS

I am currently honing my skills in Angular JS routing. After successfully implementing 2 pages routing, I now aim to achieve 3 pages routing. (function() { 'use strict'; angular .module('testTabs', ['ngMaterial&apos ...

What is the best way to perform an action on viewController1 from a button situated on viewController2?

In viewcontroller1, I have a UIScrollView that moves when the Home button is pressed to reach a specific position. The functionality works perfectly. import UIKit class ViewController: UIViewController { @IBAction func home(sender: AnyObject) { ...

Invoke a React component within a conditional statement

There is a function for exporting data in either csv or xls format based on an argument specifying the type. The functionality works flawlessly for xls but encounters issues with csv. Here's the code snippet: const exportFile = (exportType) => { ...

The request to https://sandbox.itunes.apple.com/verifyReceipt is being blocked because the origin is not permitted by Access-Control-Allow-Origin

Apple is not cooperating with my ajax requests. I'm attempting to confirm the receipt in a PhoneGap app following an in-app purchase. // preparing JSON object for Apple /* To encode the receipt data, retrieve it from the transaction’s transactionRe ...

Error in Cordova integration with Razorpay [RazorPayCheckout not found]

I'm encountering an issue where I'm getting a "RazorPayCheckout is not defined" error. I've searched on StackOverflow but couldn't find any helpful answers. Can someone please assist me with this? Thank you in advance. app.component.ht ...

Communicating between modules in Angular Js using Factories

I am currently working on a straightforward Angular application. In an effort to simplify the code, I am trying to create a globally accessible injectable library. Here is a basic overview of what I have: My app.module.js file looks like this: angular.mo ...

What is the best method for converting a variable with HTML content into a printable string?

In an attempt to display user-entered data from a text box to an HTML div, there seems to be an issue when the data contains HTML content. Instead of displaying the content as a string, it shows it as HTML elements. For example: let text = "<h1>Worl ...

Dynamically load scripts at runtime and verify their successful loading

My script file needs to dynamically import another script and utilize the functions and variables defined inside it. Currently, I am adding it to the HEAD section of the Page. However, after the addition, the functions and variables from the outer script ...

Having trouble obtaining and removing the index of a string in an array in JavaScript

As a newcomer to the world of Javascript, I am currently working on creating a memory game. However, I seem to be encountering some issues with getting this particular piece of code to function correctly. My goal is to select a random element from my ids a ...

Dealing with the name attribute in an array of ngModels in Angular 4

In this scenario, I have a class that defines hobbies and a user. Here is the structure: interface IHobby { name: string; type: string; } class User { constructor(public name: string, public hobbies: IHobby[]) { } } Now, when implementing a templa ...

Include a conditional statement in a JavaScript function to generate HTML content

Currently, I am in the process of updating a script that was originally created by someone else, and I could use some assistance since Javascript is not my primary language. This particular script is utilized within a SurveyGizmo survey, which means it may ...

Struggling to display the Three.js LightMap?

I'm having trouble getting the lightMap to show on my mesh. Here's the code I'm using: loader.load('model.ctm', function (geometry) { var lm = THREE.ImageUtils.loadTexture('lm.jpg'); var m = THREE.ImageUtils.loadT ...

Pseudo-class for clicking a button on Mobile WebKit

Currently, I am in the process of developing a private framework to replicate the iOS UI using CSS 3 and HTML 5. Most of the widgets have been created, including various colored gradient buttons, but faced with challenges when attempting to incorporate a b ...