By introducing the directive, the binding functionality becomes ineffective

Just starting out with Angular and working on a mobile app using angularjs and the ionic framework. I have an input field for project name that includes a directive to check if the name already exists, disabling data binding if it does. Any guidance would be appreciated.

 <input type="text" name="projectname" projectname-available id="projectname" ng-minlength="3"
ng-maxlength="20" ng-pattern="projectPattern" required ng-model="form.projectname" >
<div class="error-container" ng-show="authorizationForm.projectname.$invalid && authorizationForm.projectname.$touched" ng-messages="authorizationForm.projectname.$error" ng-messages-include="templates/error-list.html">
            <div class="error" ng-message="required">
                <i class="ion-information-circled"></i>
                This field is invalid!
            </div>
            <div class="error" ng-if="authorizationForm.$error.projectnameExists" >
                <i class="ion-information-circled"></i>
                Project name exists already
            </div>

        </div>

This code snippet shows the custom directive:

.directive('projectnameAvailable', function($timeout, $q,$cordovaSQLite) {
return {
 restrict: 'AE',
 require: 'ngModel',
 link: function(scope, elm, attr, model) {
   model.$asyncValidators.projectnameExists = function(projectName) {
     // Check backend for existing project name and return a promise
     query = "SELECT * FROM project WHERE name = ? ";
        $cordovaSQLite.execute(db, query, [projectName]).then(function(res1) {

            if(res1.rows.length>0) {
               exist = true;
               console.log('Project found');
              }
            else
            {
            console.log('Project not found');
             return exist = false;
             }
             }, function (err) {
                 console.error(JSON.stringify(err));
                }
             );
     var defer = $q.defer();
     $timeout(function(){
       model.$setValidity('projectnameExists', !exist);
       defer.resolve;
     }, 2000);
     return defer.promise;
   };
 }
}

Debugging:

 console.log('Project name '+$scope.form.projectname );

The output of this log statement is showing as undefined.

Plunker Link

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

Apply the cursor property to the audio element and set it as a pointer

I have a question: how can I apply a cursor style to my <audio> controls? When I try to add them using CSS, the cursor only appears around the controls and not directly on the controls themselves. Below is the code snippet: <audio class="_audio" ...

"Fixing the Vertical Order of Divs with Jquery: A Step-by-

Before I completely lose my mind, I need some help with a coding issue. Right now, I have two initial divs displayed. The user should be able to add these divs below the original ones as many times as they want, or remove them if needed. I've been att ...

What is the best way to retrieve an object using callback data with jQuery?

Using jquery with a servlet to fetch data from a database. The callback function provides raw information from the database. How can I append these values to select options in jsp? Retrive_country servlet code: String sql1 = "SELECT * FROM state WHERE co ...

Loop through each item in order to modify the text within the pop-up using a for loop

Goal Upon clicking a .player, a popup should display with relevant data about that player fetched from players.js Issue: When clicking on a player, the event seems to trigger multiple times instead of just once. This results in retrievi ...

Refresh the store value in React Flux when the route is changed

I have a straightforward setup using React and Flux. I am creating new posts with actions and stores, but the issue is that when the user navigates to another route and then returns, the this.postAdded value remains the same. The store: class NewPostsSto ...

"Trouble connecting Sequelize associations with API routes, resulting in unsuccessful retrieval of data from the database

I am currently navigating the complexities of sequelize and express, facing challenges with database associations and data retrieval. My project involves a boarders-boards (focused on surfboards and riders) database with three main models: Boards, Riders, ...

Amazon S3 is not sending the 'Access-Control-Allow-Origin' header for the requested resource

Currently utilizing reactjs and axios Encountering an issue while attempting to fetch a PNG file from S3 to the local environment. Access to fetch at 'https://xxx-xxx-xxx.s3.ap-northeast-1.amazonaws.com/0.png' from origin 'http://localhost: ...

Unable to enclose an element with an HTML structure

I am attempting to take all the elements marked with the table tag and envelop them in an HTML structure to make the tables responsive. However, it appears that my current approach is not yielding the desired results. Can you please provide some insight ...

Transferring a PHP array to JavaScript using AJAX

I have spent time searching for answers to my issue with no success. My PHP file includes the following array: $data = ['logged' => $_SESSION['loggedin'], 'sessName' => $_SESSION['name']]; echo json_encode($dat ...

Guide on sending a key to a text input field using JavaScript

How can I simulate sending a combination of keys (such as Ctrl+C or Alt+Shift) when the cursor enters an input text field using Javascript? I am not utilizing jQuery, but rather MS-Ajax. Is it achievable with MS-Ajax DOM? EDIT 1) Following @Ghostoy&apos ...

Whenever the user hits the "Enter" key, a new element will be generated and added to the bottom of an existing element

I am in need of creating a new element at the end of another element. For instance, let's say I have this element: <div id="elmtobetrig">Element that should be followed by another element when the user hits enter after this text. <! ...

Unable to fetch data using getJSON method

objecten.js var objectData = [ { image: 'gallery/objecten/bear.jpg', thumb: 'gallery/objecten/bear.jpg', title: 'my first image', description: 'Lorem ipsum caption&apos ...

Netlify encountered an error with mixed content, indicating that the page was successfully loaded over HTTPS, but it attempted to request an insecure HTTP

hey everyone, Recently, I deployed my vue-cli website project on Netlify. However, upon opening the website, I encountered the following error message: Mixed Content: The page at 'https://xxxx.netlify.app/' was loaded over HTTPS, but requested a ...

Exploring the benefits of utilizing EmberJS within the metalsmith.IO platform

Trying to integrate EmberJS into a codesmith.IO project previously built with Angular 1. Feeling like I'm overlooking something simple when it comes to the implementation process. Since I typically use Ember CLI for new app templates, I'm unsure ...

What could be causing my state not to change in Nextjs even though I followed the quick start guide for Easy Peasy?

I recently encountered an issue while trying to implement easy peasy for global state management in my nextjs app. The problem I faced was that the state would only update when I changed pages, which seemed odd. To better understand what was going on, I de ...

Issues with Semantic UI Calendar not displaying properly

I am currently experimenting with the Semantic UI Calendar, where there is a date input field and a calendar that pops up when selected as demonstrated in this initial example. Since I am not familiar with this process, I am uncertain if I have properly li ...

How can I automatically copy a highlighted link in HTML?

I am attempting to implement a feature where users can click on a link and have it automatically copied. For example, I want it to appear like this: "UPI ID: david@okidfcbank". In this case, the link should be highlighted in blue. This is the code I have ...

Combining Two Arrays Based on Unique Identifier

Seeking guidance on enhancing this method to eliminate the need for a workaround. I have two separate Object Arrays containing JSON data. The first array consists of all dates within a specific range, while the second array is derived from a SQL query, po ...

Transform yaml strings into JSON entities

We are facing a challenge with two separate codebases that have different localization styles. One codebase uses yaml, while the other uses JSON. Currently, we are working on transitioning to the JSON-based codebase. However, with 20k yaml strings and sup ...

Wordpress-inspired navigation on the left

Currently, I am in search of a JavaScript library, preferably built with jQuery, that can replicate the functionality of the left menu bar in WordPress when a user is logged in. This menu features images with text, the ability to expand and collapse, a ho ...