When working with AngularJS, I encountered an issue where I added two additional input text boxes with unique IDs and ng-models, but unfortunately

After countless modifications to a form, I am puzzled as to why two additional fields are not being sent this time.

Controller

vm.question = {};

Although most of the time these fields will be empty, I have never encountered an issue with sending blank field values before.

Existing field that is functioning properly

<div class="form-group">
   <label class="col-md-2" for="english">Spanish</label>
   <div class="col-md-10">
     <input type="text" ng-model="vm.question.VerbiageSpanish"
             id="verbiagespanish" name="verbiagespanish"
             class="form-control"
             placeholder="Spanish" />
   </div>
</div>

Newly added fields to the form with ng-model but failing to submit upon saving

<div class="form-group">
   <label class="col-md-2" for="english">Parent ID</label>
     <div class="col-md-10">
       <input type="text" ng-model="vm.question.ParentId"
             numbers-only style="width:30px" id="parentid"
             name="parentid" class="form-control" />
     </div>
 </div>
<div class="form-group">
     <label class="col-md-2" for="english">Parent Value</label>
     <div class="col-md-10">
     <input type="text" ng-model="vm.question.ParentValue"
            style="width:220px" id="parentvalue" name="parentvalue" 
            class="form-control"
            placeholder="Parent Value" />
     </div>
</div>

Looking at the code example, it appears that VerbiageSpanish and other existing fields are present except for the new ParentId and ParentValue. How could this be happening?

{
  "Active": true,
  "Name": "test",
  "Description": "test",
  "Verbiage": "test",
  "VerbiageSpanish": "test",
  "directive": {
    "1": true
  },
  "data": {
    "1": "yes"
  },
  "SortOrder": {
    "1": "2"
  }
}

Update based on received feedback:

  1. If I populate the ParentId and ParentValue fields, they do get sent over as I verified through console.log

  2. Form submit button

     <button type="button" class="btn btn-success" data-dismiss="modal"
             ng-click="vm.saveQuestion(vm.question)">
        Save
     </button>
    
  3. The controller sends all data to a service, so clearly there is no API communication when the fields are left empty

    vm.saveQuestion = function (script) {
        var promise = "";
        console.log('savequestion debug', script);
    

Upon entering data in those textboxes, here's what I observed

{
  "Active": true,
  "Name": "test",
      "ParentId" : "22",
      "ParentValue": "afafaf",
  "Description": "test",
  "Verbiage": "test",
  "VerbiageSpanish": "test",
  "directive": {
    "1": true
  },
  "data": {
    "1": "yes"
  },
  "SortOrder": {
    "1": "2"
  }
}

Answer №1

In order to properly initialize those keys, consider adding the following code in your controller:

vm.question.VerbiageSpanish = "";
vm.question.ParentId = "";
vm.question.ParentValue = "";

Alternatively,

You can also utilize ng-init="" for those fields:

<input type="text" ng-model="vm.question.ParentValue"
       style="width:220px" id="parentvalue" name="parentvalue" 
       class="form-control"
       ng-init="" placeholder="Parent Value" />

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

Customizing the input placeholder for password fields in IE8 using jQuery

Currently, I have opted to use jQuery instead of the HTML5 placeholder attribute <input type="text" name="email" value="Email" onfocus="if (this.value == 'Email') { this.value = ''; }" onblur="if (this.value == '') { this. ...

Unable to decrease the width of a div element in Vuetify and Nuxt

As I work on creating a dynamic form with fields that need to occupy only 50% of the size of a regular field, I encounter different components based on data provided by Vuex. The use of v-for in Vue.js helps me loop through form objects and render the app ...

What causes the error "property does not exist on type" when using object destructuring?

Why am I encountering an error in TypeScript when using Object destructuring? The JavaScript code executes without any issues, but TypeScript is showing errors. fn error: This expression is not callable. Not all elements of type '(() => void) | ...

Implementing Kendo UI dataSource to interact with a PHP function

Greetings Everyone, I have a category.php file within my code that handles CRUD functions. However, I am unsure how to call these functions in the Kendo UI dataSource/transport. Previously, I had separated the PHP files, but now I want to consolidate them ...

Despite locating the button, Protractor still encounters difficulties when attempting to click on it

I've been having trouble clicking on a button using Protractor. The issue is that even though the driver can locate the element, it still won't click on it. Any assistance would be greatly appreciated. Thank you in advance. Here is the HTML for ...

Using ExpressJS to generate a page with inputs

Using ExpressJS, I have created an Object of the IndexController in my router (index.js) and passed a String as a constructor argument. I then attempted to call the showDefaultFeed method. Expected output from "index.hbs" view was to print the argument pa ...

Developing web applications using AngularJS and Web API allows for customization of error handling by utilizing

Here I have a simple form that includes only one input field for the user's name. However, I want to make sure that there are no duplicate entries in the table. I can easily check this on the server side and send a custom message in the response head ...

Create queries for relays in a dynamic manner

I'm using Relay Modern for my client GraphQL interface and I am curious to know if it is possible to dynamically generate query statements within Relay Modern. For example, can I change the original query structure from: const ComponentQuery = graphq ...

JQuery animations not functioning as expected

I've been attempting to create a functionality where list items can scroll up and down upon clicking a link. Unfortunately, I haven't been able to achieve the desired outcome. UPDATE: Included a JSFiddle jQuery Code: $(document).ready(function ...

Reset functionality for input selector is malfunctioning

My HTML code looks like this: <input type="number"> <br> <input type="number"> <br> <input type="number"> <br> <button>+</button> In my JS script, I have the following: $('input').on('c ...

Tips for establishing and connecting numerous connections among current nodes using the same criteria

While browsing StackOverflow, I came across similar questions. However, I believe this one has a unique twist. The main issue at hand is: How can I establish multiple relationships between existing nodes? I have the following code snippet: session . ...

What causes the discrepancy in calculating marginTop on a desktop browser compared to a mobile browser?

In the top screenshot, you can see a representation of my Pixel 6XL connected to my laptop in USB debug mode. The checkered area represents the URL bar on the Chrome browser displayed on my Pixel device. Below that, the second screenshot shows the view fr ...

Is there a way to implement a JavaScript || operator alongside ng-class in AngularJS?

I am attempting to apply a class in this way: ng-class="{fa-disabled: cursorWait || wos.wordFormRowIsDisabled(wf)}" I want the fa-disabled class to be included if either cursorWait is true or if the wos.wordFormRowIsDisabled function returns true. Howev ...

Exploring the usage of multidimensional arrays in React components

How can I extract data such as teamId from the "teams" array using datas.map() method in a multidimensional array? Any tips or help would be appreciated. Is there another way to map out this data? { "gameId": 3226262256, "platformId": "NA1", " ...

Leveraging Gatsbyjs to Integrate GraphQL Data with Material UI Library

Just starting out as a Frontend Developer and currently learning Gatsbyjs along with the Material UI library. I'm working on creating a new page using the Material UI Gatsby Starter code available here. However, I've encountered an issue when tr ...

Having trouble with nested ng-repeat not working properly when trying to parse JSON data from a WordPress site

I am currently in the process of developing a news application using Ionic. The news content is being fetched from a Wordpress site in JSON format. Here is a snippet of the JSON data. { "status": "ok", "count": 100, "count_total": 4104, "pages": 42, "pos ...

My desire is for every circle to shift consecutively at various intervals using Javascript

I'm looking to draw circles in a sequential manner. I am trying to create an aimbooster game similar to . Instead of drawing all the circles at once, I want each circle to appear after a few seconds. The circles I've created currently do not g ...

Transferring information from child to parent class in TypeScript

I have a scenario where I have two classes (Model). Can I access properties defined in the child class from the parent class? Parent Class: class Model{ constructor() { //I need the table name here. which is defined in child. } publ ...

PHP returns the result of form submission to JavaScript, allowing for distinction between successful and unsuccessful outcomes

JavaScript: $("#register-form").submit(function(event) { event.preventDefault(); $.post("./register.php", { username: $("#username").val(), password: $("#password").val(), passwordtwo: $("#passwordtwo").val(), email: $ ...

Unexpected behavior of ion-select: No rendering of selected value when applied to filtered data

I came across an unexpected issue with the dynamic data filtering feature of ion-select. In my application, users are required to choose three unique security questions during registration. I have an array of available questions: questions: Array<{isSe ...