Having trouble modifying the Input with split() in angularJS

I am faced with a nested JSON object that contains an array as one of its properties. Each item in the array is separated by a ';'.

My goal is to use ';' as a delimiter to split each array item and make necessary changes. However, I am having trouble editing the splitted array items.

After making the changes, I need to join them back together as they were originally. The issue lies in splitting the array item based on the delimiter but not being able to edit it.

Here is my JSON object:

{
    name:"test1",
    xdata:["1;2;3","abhsad"]
}

You can view the code on Plunker: http://plnkr.co/edit/VYTQ6jvJ1bCKosRXh2Nt?p=preview

Answer №1

While it may seem a bit complex, achieving this is still within reach. The process involves utilizing two ngRepeat loops along with some ngInit/ngChange manipulations to initialize and update certain elements:

angular.module('demo', []).controller('DemoController', Ctrl);

function Ctrl($scope) {
  $scope.group = {
    name: "test1",
    xdata: ["1;2;3", "abhsad"]
  }
}
<script src="//code.angularjs.org/1.5.5/angular.min.js"></script>

<div ng-app="demo" ng-controller="DemoController">

  <div ng-repeat="(i, val) in group.xdata track by $index" 
       ng-init="parts = val.split(';')">
    
    <input type="text" 
           ng-model="part" 
           ng-repeat="(j, part) in parts track by $index" 
           ng-change="parts[j] = part; group.xdata[i] = parts.join(';')">
  </div>

  <pre>group = {{group | json}}</pre>
</div>

Answer №2

To handle each individual value, a separate model needs to be created. This model will then update the corresponding model when the value in the text box is changed. Afterwards, a function can be written to update the xData values.

Check out this example plnkr http://example.com/sample

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

JavaScript - Receiving alert - AC_RunActiveContent.js needed for this page to function

When I attempt to open the HTML file in my application, a pop-up message appears stating that "This page requires AC_RunActiveContent.js." However, I have already imported and referenced the AC_RunActiveContent.js file in my package. Can someone assist m ...

How to nullify the valueChanges pipe in Angular RxJS until the observable is resolved

A challenge I am facing is piping the valueChanges from a select element to trigger the appropriate API request and displaying a spinner until the response is received. Additionally, I am trying to utilize publish() and refCount() methods so that I can use ...

Vue.js Components Facing Build Issues

I am currently experiencing a puzzling phenomenon. While working on my application components using Laravel Jetstream and Inertia Stack with VueJS, I encountered an issue where a newly created component in the same folder as others was not building. Neithe ...

Angular parse:syntax ERROR - An unexpected issue has been encountered

I encountered an issue while attempting to retrieve data from a MySQL database using AngularJS. angular.js:13708 Error: [$parse:syntax] http://errors.angularjs.org/1.5.7/$parse/syntax?p0=Code&p1=is%20an%20unexpected%20token&p2=7&p3=x.Zip%20Cod ...

Struggling to display filtered content in React using State

As a newcomer to React, I am working on a todo list that shows both current and completed tasks using LocalStorage. Each task has a boolean property called "active" which is toggled when a user clicks on the task checkbox. I have a filter in place to separ ...

What is the best way to store multiple forms in a single request using React?

Is there a more efficient way for me to save multiple forms in multiple child components from the parent component using just one API request? I have attempted to utilize Context and reducer, which did work. However, I am unsure if this is the best approa ...

Enhance the step implementation in Cucumber-js

Background In my TypeScript project, I am utilizing https://github.com/cucumber/cucumber-js. The code snippet below showcases a typical cucumber implementation: import { Given, Then, When } from 'cucumber' Given(`Page is up and run ...

Having Issues with Loading More Button Functionality in Selenium Automation

Here is a snippet of my code. from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected ...

Ways to retrieve an input field value without triggering form submission

I'm currently working on a payment form where users input the amount in a text field. I also have another text field on the same form that should automatically display the amount in words based on the user input. However, I'm struggling to figure ...

Modify the website address and show the dynamic content using AJAX

$(function(){ $("a[rel='tab']").click(function(e){ //capture the URL of the link clicked pageurl = $(this).attr('href'); $("#Content").fadeOut(800); setTimeout(function(){ $.ajax({url:pageurl+'?rel=tab&apo ...

In regards to the preceding element within an array composed of strings

Recently, I've started learning Java and I've encountered a challenge with arrays. Below is the code that I'm currently working on. String english = "hip-hop"; String[] words = english.split ("[\\s+]|(?<=-)|(?=-)"); Str ...

Assign an attendee the role of organizer in the Google Calendar API

I am currently utilizing the googleapis npm package to facilitate calendar event creation. Below is my request payload for calendar.events.insert in order to generate an event: { "summary":"Biology class", "location":"Google Meet: Please follow the go ...

Is there a way to prompt the native browser message for HTML5 form validation on a custom element?

Can the native validation UI be activated on non-default input elements like divs or similar? I want to develop a custom React element with validation without relying on hidden or invisible input fields. ...

Looping through the ajax data to populate ion-item elements

I am currently working on a loop that retrieves user IDs, names, etc. from a JSON file. I am trying to display this data in a list view within an Ionic framework. When I simply use direct alerts in JavaScript, the users are displayed correctly, but when I ...

What is the best way to link function calls together dynamically using RXJS?

I am seeking a way to store the result of an initial request and then retrieve that stored value for subsequent requests. Currently, I am utilizing promises and chaining them to achieve this functionality. While my current solution works fine, I am interes ...

The largest contentful paint is anticipating an unidentified event

My website is encountering issues with Google Pagespeed and I'm unsure of the cause. The primary bottleneck appears to be the LCP time, which Google reports as taking between 7 and 11 seconds during each test. Upon analyzing the waterfall chart, it ...

Is there a way to convert a JSONObject to a .csv file in GWT?

I'm brand new to GWT, so please forgive me if this is a basic question, but I can't seem to find the solution. I have a function that works fine and allows me to export a table as .xlsx file. Everything is going smoothly with this process. I am u ...

Ways to bypass browser pop-up blockers when using the window.open function

I am displaying an HTML retrieved from the backend. printHtml(htmlContent) { var windowToPrint = window.open('', '_blank'); windowToPrint.document.write(htmlContent); setTimeout(function () { windowToPrint.document ...

Installing Eclipse for PHP and JavaScript on your computer is a simple process. Here

Currently, I am working on a web project that consists mostly of PHP and JavaScript files, as well as some HTML and CSS files. I have decided to use Eclipse as my Integrated Development Environment (IDE) for this project. However, upon visiting eclipse.org ...

The ion-datetime in Ionic 4 ensures that the floating label always remains visible, even when the input

When an ion-datetime field in Ionic 4 has no value, the label always floats as shown below. Here is my code snippet: <form [formGroup]="statusHandlerForm"> <ion-item class="input-container " align-items-center no-padding> <ion-la ...