Implementing a dynamic dropdown menu using AngularJS and jQuery

Check out my PLNKR CODE

Issue -

I'm attempting to create a dynamic label and textarea option where:

  1. If a user picks "Work," then when they click the "+" icon, the next selection will only include ["Cell", "Home", "Fax"].
  2. Then if "Home" is selected, on clicking the "+" icon from the second selection, the following options will only be ["Cell", "Fax"] and so forth.

However, I am struggling because my first array is decreasing and no data is appearing in the subsequent select options.

Please let me know what mistake I might be making and any suggestions on how to correct it are also appreciated.

Answer №1

It seems like your $scope.temp variable contains the right number of objects. The issue might be arising from how you are generating the new select options after clicking the plus button. Instead of attempting to create the element using a jQuery constructor, consider utilizing a custom directive for better functionality.

Using a custom directive could provide a more efficient solution in this scenario.

Answer №2

Shift ng-click over to the <a> tag, while also incorporating ng-model="target" into the textarea:

<select ng-model="contact"
        ng-options="selOption.value as selOption.name for selOption in selOptions"
        ng-init="contact = selOptions[0].value"></select>
<textarea ng-model="target"></textarea>
<a href="#" ng-click="shiftArr()"><img src="..." id="plusbutton"></a>

Within the controller, set up the initialization of $scope.target, and make necessary adjustments to $scope.shiftArr:

$scope.target = '';

$scope.shiftArr = function() {
    var arrVal = $scope.contact;
    var newArr = [];
    newArr = $scope.selOptions;
    for (var i = 0; i < newArr.length; i++) {
        if (newArr[i].value === arrVal) {
            $scope.target = $scope.target + newArr[i].name + '\n'; 
            var index = arrVal - 1 ;
            newArr.splice(index, 1);
            $scope.temp = newArr;
        }
    }
};

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

Is the data set in stone, or is it just the API data that can

Recently, I embarked on the journey of creating a blog using nextjs, MongoDB, and express. Taking advantage of getStaticProps and getStaticPaths, I was able to dynamically generate pages for each blog post and display them individually. However, I encoun ...

The system encountered an error stating that the required component "Footer" in the main directory was not located in the specified node_modules

Issue I'm Facing: Error found in components/main/Footer within the file path: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue Components Tree as shown in the screenshot below: https ...

.mounted middleware's redirect() function fails when using a relative destination

I need to limit access to a specific subtree only to users who have been authenticated. The setup looks like this: app.use(express.bodyParser()) .use(express.cookieParser('MY SECRET')) .use(express.cookieSession()) .use('/admin', is ...

Ways to toggle the visibility of a div based on checkbox changes in Angular:

Can you show and hide a span using checkboxes in Angular? When the checkbox is checked, the span should be displayed, and when it is unchecked, the span should not be displayed. Check out this fiddle here: http://jsfiddle.net/d9uc1dxc/2/ <div class="f ...

Can anyone share tips on implementing animations during transitions when using $location.path for redirection in AngularJS?

In my project setup, I am utilizing AngularJS for the structure and backend functionalities, while JqueryM is being used for the UI design elements. Currently, I'm redirecting using $location.path with ng-click. Is there a method to incorporate JQM d ...

Screen proportions altered - Background image disappearing | Unusual occurrences |

If you look at my site everything seems to be ok, ... untill you minimize the website. A horizontal scrollbar appears and when you use that scrollbar, you will see that my image has vanished. My Website I made that image responsive...so i have no idea wh ...

What is the best way to add a background to text that has been wrapped?

How can I achieve a background effect for text that is wrapped within a container using CSS? Is it possible to do this by referring to an image like this: . ...

Align the HTML element to the right edge of its sibling element that is centered on the

Is it possible to achieve a specific layout using CSS where there is text inside a centered div, and underneath that, another div with right-aligned text? I'm unsure if this can be done effectively. I am currently unaware of how to accomplish this us ...

Angular 4 with Typescript allows for the quick and easy deletion of multiple selected rows

I am currently working on an application where I need to create a function that will delete the selected checkboxes from an array. I have managed to log the number of checkboxes that are selected, but I am struggling to retrieve the index numbers of these ...

Tips on revealing concealed information when creating a printable format of an HTML document

I need to find a way to transform an HTML table into a PDF using JavaScript or jQuery. The challenge I'm facing is that the table contains hidden rows in the HTML, and I want these hidden rows to also appear in the generated PDF. Currently, when I co ...

Converting an array object into a specific format: step-by-step guide

The data I am receiving from the backend is in an array object format. How can I transform it into a particular data format? For example: data = [ { name: value, age: value, phoneNumber: value, email: value }, { name: value, age: value, phoneNumber: va ...

Switch between classes based on the query using the Ajax response

In order to retrieve data from a database and determine if the field "is_recurring" is set to 1 or 0, I am utilizing an ajax call to my functions.php file. This value is based on a selection made in a dropdown menu. Depending on the result returned by the ...

Guide to using vite-plugin-rewrite-all in conjunction with Quasar for Vue 3 - or alternative method to enable periods in paths

Encountering a 404 error when using quasar+vite in vueRouterMode: 'history' mode with paths containing a period/dot in the id? This issue has been discussed in various places: https://github.com/vitejs/vite/issues/2415 https://github.com/vitejs/ ...

I am looking to switch the input border-bottom color to blue when the input field is focused or has valid content

Can someone help me change the border bottom color of my input to blue in the following HTML code: .inputBox input:focus ~ input, .inputBox input:valid ~ input{ border-bottom: 1px solid #0000cd; } <div class="i ...

Customizing the appearance of pagination numbers in ReactJS by altering their color

I am currently working on a pagination ReactJS App. Check out the app here: https://codepen.io/claudio-bitar/pen/VERORW One specific feature I would like to implement is changing the color of the current page number in the pagination. For example, if th ...

Generating random numbers for ids in C# by clicking a button

Utilizing c# winforms and selenium webdrivers. I attempted the following driver2.FindElement(By.XPath("//div[@class='ad-ttl']/a")).Click(); to try to click it unsuccessfully. HTML Code : <div id="yui_3_10_0_1_1418194162300_146" class="a ...

Implement a feature that adds a circle element when an image is clicked in a React application

I am attempting to create a program that allows users to add circles to an image by clicking on it. Essentially, when the user clicks at coordinates (x,y), a circle with a radius of 10 will appear at that location. I am exploring ways to implement meta-pro ...

Can we expect every bullet point to be consistently indented at precisely 1.8em?

Recently, I created a dropdown menu using only CSS. The challenge was to have a horizontal bar of items that can each expand into a vertical menu. However, I wanted the expanded menus to display bulleted lists instead of tertiary menus. By nesting three ul ...

Highchart tip: How to create a scrollable chart with only one series and update the x-axis variable through drilldown

Before I pose my question, here is a link to my jsfiddle demo: http://jsfiddle.net/woon123/9155d4z6/1/ $(document).ready(function () { $('#deal_venue_chart').highcharts({ chart: { type: 'column' ...

Discovering a precise object from an array in MongoDB

Let's consider a scenario with the following MongoDB document: { "_id": { "$oid": "628f739398580cae9c21b44f" }, "place":"Amsterdam", "events": [ { "eventName": ...