Uploading Massive Form Data Using Angular JS

After spending countless hours on this project, I still can't figure out how to post data into a table using JavaScript objects. While I can easily work with smaller data sets, I'm struggling with handling multiple nested objects.

EDIT: The main issue I'm facing is that the data from the submission form is not getting posted to the table when the submit button is clicked. I need to be able to add multiple entries to the table and then include quotes and proposals later on.

Additionally, it would be great if someone could guide me through working with nested JavaScript objects, especially when using Angular. Most resources focus on single objects rather than dealing with nested structures.

If you could shed some light on why my current approach isn't working and suggest alternative methods, I would greatly appreciate it. Here's the link to the CodePen: CodePen

Javascript

(function () {
        // JavaScript code goes here...
    })();
    

HTML

<body ng-app="app" ng-controller="CustomerCtrl as cust">
        <h2> Customers </h2>
        <table>
          <tbody>
            <tr>
              <th>Customer</th>
              <th>Phone</th> 
              <th>Email</th>
              <th>Address</th>
              <th>Proposals</th>
              <th>Quotes</th>
            </tr>
            <tr ng-repeat="customer in cust.customers">
              <td> {{customer.customer}}</td>
              <td> {{customer.phone}} </td>
              <td>{{customer.email}}</td>
              <td>
                  <ul class="address"> 
                    <li> {{customer.address.line1}} </li> 
                    <li> {{customer.address.city}}, {{customer.address.state }}, {{customer.address.zip}}</li>
                 </ul> 
              </td>
              <td>
                 <ul >
                    <li ng-repeat="prop in customer.proposals">{{prop.project_title}}</li>
                 </ul>
              </td>
              <td>
                <ul >
                    <li ng-repeat="quote in customer.quotes ">{{quote.quote_num}}</li>
                 </ul>
              </td>
           </tr>
         </tbody>
       </table>

      <div>
      <form novalidate class="simple-form" ng-submit="cust.AddCustomer(new)">
        <h2> Add A Customer</h2>
        <label> Customer Name:</label><input type="text" ng-model="customer" /><br/>
        <label>Customer Email:</label><input type="email" ng-model="email" /><br/>
        <label>Customer Phone:</label><input type="text" ng-model="phone" /><br/>
        <label>Customer Address:</label><input type="text" ng-model="line1" placeholder="Address/ PO Box"/><br/>
        <input type="text" ng-model="city" placeholder="City" /><br/>
        <input type="text" ng-model="state" placeholder="State"/><br/>
        <input type="text" ng-model="zip" placeholder="Zip" /><br/><br/>
        <button type="submit"> Submit </button> 
      </form>
    </div>

      <div class="newCustomerData">
        <h2> The Customer You're Adding: </h2>
        <div><strong>Name:</strong> {{customer}} </div>
        <div><strong>Email:</strong> {{email}} </div>
        <div><strong>Phone:</strong> {{phone}} <</div>
        <div><strong>Address:</strong> {{line1}}<br/> {{city}}, {{state}} {{zip}} </div>
      </div>

  </body>

Answer №1

It seems like you are calling AddCustomer(new) correctly, but your form is not capturing input data into the 'new' object as expected. Make sure to add a dot notation to your ng-models referencing the 'new' object:

<label> Customer Name:</label> <input type="text" ng-model="new.customer" /><br />
<label>Customer Email:</label> <input type="email" ng-model="new.email" /><br />
<label>Customer Phone:</label> <input type="text" ng-model="new.phone" /><br />
<label>Customer Address:</label> 
<input type="text" ng-model="new.line1" placeholder="Address/ PO Box"/><br />
<input type="text" ng-model="new.city" placeholder="City" /><br />
<input type="text" ng-model="new.state" placeholder="State"/><br />
<input type="text" ng-model="new.zip" placeholder="Zip" /><br /><br/>

Answer №2

When filling out the form, make sure your inputs are binding to JavaScript objects at the correct scope. Specifically, ensure you are accessing data from the newcust object by adding newcust. to your ng-model.

Here's an example:

<input type="email" ng-model="newcust.email" />

Instead of:

<input type="email" ng-model="email" />

Additionally, for the address field, include newcust.address like this:

<input type="text" ng-model="newcust.address.line1" placeholder="Address/ PO Box"/><br />

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

Utilizing ng-click within ng-repeat along with $index

I'm experimenting with using ng-click on a div that is part of an ng-repeat loop, utilizing $index as seen in the code below : HTML: <div class="elementContainer" ng-repeat="element in elements" ng-click="elementUrl($index)"> <h2>{{ ...

Troubles with Angular elements not aligning correctly when using the "display: block" property

When using an angular element for a directive with "display: block", it may not automatically take up 100% of the width of the parent container. In order to ensure that it does, the width must be explicitly set to "100%" in the CSS. Despite setting "width: ...

Tips for navigating the material ui Expanded attribute within the Expansion Panel

After looking at the image provided through this link: https://i.stack.imgur.com/kvELU.png I was faced with the task of making the expansion panel, specifically when it is active, take up 100% of its current Div space. While setting height: 100% did achi ...

Using blending modes with gradient colors in an SVG design

I'm struggling to get my logo to change colors upon scrolling into a button with similar gradient colors, but I just can't seem to make it work. Can anyone lend me a hand? Thank you! Take a look at my Logo. I've attempted to add some styles ...

Unable to retrieve function variables stored in fancytree source nodes within its activate method

If the configuration of my fancytree includes a source like this: source: [{ title: "Item1", key: "1", myFunc: function (item) { return 'function'; ...

Converting a Perl hash into a JavaScript hash: A comprehensive guide

I am currently using the template toolkit framework and working with a Perl hash data type in my tt file. My goal is to convert this Perl hash data type into a JavaScript hash data type. Code: template: [% PERL %] use JSON qw(encode_json) ...

Can one jQuery script be used for multiple ajax 'like' buttons?

Hey there! I'm working on an Ajax 'like' button that utilizes jQuery. This button will be utilized multiple times on a single page. I'm looking for a way to streamline the process and avoid including the jQuery script multiple times. Is ...

Guide for building a Template-driven formArray in Angular

I am currently implementing a fixed number of checkboxes that are being bound using a for loop. <ul> <li *ngFor="let chk of checkboxes"> <input type="checkbox" [id]="chk.id" [value]="chk.value&q ...

Unable to assign value to Angular scope variable

Currently, I am delving into Angular JS as a learner. My attempt at using $http to set the corresponding value to the scope variable seems to be failing. Below is a snippet of the HTML code I am working with: <div ng-app="fileapp" ng-controller="myctl" ...

Choosing an option from a dropdown menu in Google Forms using Puppeteer in NodeJS

Hey everyone, I've been working on automating a Google form and I'm facing an issue with a dropdown menu. I'm struggling to select the desired value from the dropdown list. When I use Puppeteer to type in "United space Kingdom," it autocomp ...

AngularJS - Calculate multiple currencies

I need to calculate the product of a value and months. For the input value, I am utilizing a Jquery Plugin to apply a currency mask. Unfortunately, the calculations are not functioning properly with this plugin. My goal is to multiply the value, includin ...

Firestore Query sends data object to browser

When making a Firestore query, the browser is displaying [object Object],[object Object] instead of the expected output: router.get('/jobopportunities', async(req, res) => { var jobArray = []; const snapshot = await fireba ...

Tips on maintaining a constant number of elements displayed within a container while scrolling using *ngFor

In an effort to improve the performance of loading a large amount of data inside a container div, I implemented a solution. It initially worked fine, but as I continued to append elements to the list while scrolling down, it started to slow down significan ...

How about this: "Unveil the beauty of dynamically loaded

var request = new Request({ method: 'get', url: 'onlinestatusoutput.html.php', onComplete:function(response) { $('ajax-content').get('tween', {property: 'opacity', duration: 'long&apos ...

Experiencing difficulty adjusting the width of a Tumblr post with JavaScript or jQuery?

Calling all coding experts! I've been working on customizing a Tumblr theme, and everything is looking good except for one issue. I'm struggling to adjust the width of photos on a permalink (post) page. Check out this link: You'll notice t ...

Have you ever encountered the orientationchange event in JavaScript before?

When does the orientationchange event trigger in relation to window rotation completion? Is there a way to fire an event before the operating system initiates the integrated window rotation? Edit: For example, can elements be faded out before the rotation ...

Sending an HTML form data to a Node.js server

I'm currently working on a simple project that involves creating a web form and sending it to node.js in order to save the information received. I've been following some YouTube tutorials (https://www.youtube.com/watch?v=rin7gb9kdpk), but I' ...

The create document feature seems to be malfunctioning for some reason. Any ideas why it's not working properly in Firebase with Angular

I've been attempting to submit user data to the Firebase Firestore database, but I'm experiencing issues with the function that is supposed to create a new collection. Despite trying different methods, none of them seem to be working for me. I ha ...

Submitting data from a JavaScript frontend to a PHP backend

I've exhausted all options in attempting to resolve this issue. The javascript code is designed to send a list of product IDs to a PHP page. When products are selected, the submit button should activate the submit function. function submit() { ...

generate a collection using a string of variables

I'm looking for a way to pass a string as the name of an array to a function, and have that function create the array. For example: createArray('array_name', data); function createArray(array_name, data){ var new_array = []; // pe ...