Modifying the item using JHipster's modal feature

Using JHipster has made my project creation a smooth process so far. However, I encountered an issue with editing objects on my main.html. While I can successfully edit posts on the posts.html page that the router directs to, I am unable to do so with the same code on my main.html. Even though I can retrieve information from the postController on my main page and display it correctly, the data doesn't appear inside the modal popup. The console.log($scope.post) confirms that the object needed for editing is retrieved by the controller, but it's not transmitted to the modal. Any help would be appreciated.

Button triggering the edit:

//inside postController and an ng-repeat of posts calling update function
<button class="btn btn-primary btn-xs" type="submit" ng-click="update(post.id)" class="btn">
    <span class="glyphicon glyphicon-pencil"></span> Edit
</button>

Modal Code:

<div ng-controller="postController">
            <textarea class="form-control" rows="3" placeholder="Status update here..." data-toggle="modal" data-target="#savePostModal" ng-click="clear()"></textarea>
            <div class="modal fade" id="savePostModal" tabindex="-1" role="dialog" aria-labelledby="myPostLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <form name="form" role="form" novalidate class="ng-scope ng-invalid ng-invalid-required ng-dirty ng-valid-minlength" ng-submit="create()">

                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="clear()">&times;</button>
                                <h4 class="modal-title" id="myPostLabel">Create or edit a Post</h4>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    <label>ID</label>
                                    <input type="text" class="form-control" name="id" ng-model="post.id" readonly>
                                </div>

                                <div class="form-group">
                                    <label>Title</label>
                                    <input type="text" class="form-control" name="test" placeholder="Title your post..." ng-model="post.name" ng-minlength=1 required>
                                </div>

                                <div class="form-group">
                                    <label>Author</label>
                                    <input type="text" class="form-control" name="test" placeholder="Temporary Field..." ng-model="post.author" ng-minlength=1 required>
                                </div>

                                <div class="form-group">
                                    <label>Text</label>
                                    <textarea rows="8" placeholder="Status update here..." class="form-control" type="text" name="test" ng-model="post.text" ng-minlength=1 required></textarea>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="clear()">
                                    <span class="glyphicon glyphicon-ban-circle"></span> Cancel
                                </button>
                                <button type="submit" ng-disabled="form.$invalid" class="btn btn-primary">
                                    <span class="glyphicon glyphicon-save"></span> Save
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

Update function:

$scope.update = function (id) {
        $scope.post = Post.get({id: id});
        $('#savePostModal').modal('show');
    };

Even though the get function is being called successfully, the data from $scope.post isn't being utilized.

Answer №1

It appears that for a modal to function properly, it must reside within the same controller-div as the text that triggers the button. This is likely due to the differing scopes on controllers if the divs are separate. Additionally, avoid having a second modal with the same name for testing purposes, as it will lead to failures caused by confusion over which function to use.

<div id="toBeUpdated" ng-controller="postController">
   <div class="modal fade" id="savePostModal" tabindex="-1" role="dialog" aria-labelledby="myPostLabel" aria-hidden="true">
      <div class="modal-dialog">
         <div class="modal-content">
            <form name="form" role="form" novalidate class="ng-scope ng-invalid ng-invalid-required ng-dirty ng-valid-minlength" ng-submit="createMob()">
               <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="clear()">&times;</button>
                  <h4 class="modal-title" id="myPostLabel">Create or edit a Post</h4>
               </div>
               <div class="modal-body">
                  <div class="form-group">
                     <label>ID</label>
                     <input type="text" class="form-control" name="id" ng-model="post.id" readonly>
                  </div>
                  <div class="form-group">
                     <label>Title</label>
                     <input type="text" class="form-control" name="test" placeholder="Title your post..." ng-model="post.name" ng-minlength=1 required>
                  </div>
                  <div class="form-group">
                     <label>Author</label>
                     <input type="text" class="form-control" name="test" placeholder="Temporary Field..." ng-model="post.author" ng-minlength=1 required>
                  </div>
                  <div class="form-group">
                     <label>Text</label>
                     <textarea rows="8" placeholder="Status update here..." class="form-control" type="text" name="test" ng-model="post.text" ng-minlength=1 required></textarea>
                  </div>
               </div>
               <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="clear()">
                  <span class="glyphicon glyphicon-ban-circle"></span> Cancel
                  </button>
                  <button type="submit" ng-disabled="form.$invalid" class="btn btn-primary">
                  <span class="glyphicon glyphicon-save"></span> Save
                  </button>
               </div>
            </form>
         </div>
      </div>
   </div>
   <li class="animate-repeat" ng-repeat="post in posts.slice().reverse() | checkboxAndFilter:search.$:search.author:search.name:search.id:search.text | limitTo: noPostsOnPage">
      <div class="well ng-scope">
         <div name="desktopPost" class="h4">
            <input type="checkbox" name="checkered"> &emsp;{{post.name}}&emsp;&emsp; <span ng-if="post.summary==1" class="animate-if"><button class="btn btn-xs disabled"><span class="glyphicon glyphicon-star-empty"></span></button></span>
            <a class="pull-right" ng-click="changeid(post.id);alignSearch();">{{post.id}}</a>
         </div>
         <div style="display: none" name="mobilePost" class="h4">
            <div ng-click="postNameAlert(post.name);">
               <div name="ellipse" style="white-space: nowrap; overflow: hidden;text-overflow: ellipsis;-o-text-overflow: ellipsis;">{{post.name}}</div>
            </div>
            <input type="checkbox" name="checkered"> &emsp; 
            <span ng-if="post.summary==1" class="animate-if"><button class="btn btn-xs disabled"><span class="glyphicon glyphicon-star-empty"></span></button></span>
            &emsp;&emsp; 
            <a class="pull-right" style="padding-top:7px" ng-click="changeid(post.id);alignSearch();">{{post.id}}</a>
         </div>
         <p>
         <div ng-bind-html="trustHtml(post.text)" hashtagify term-click="tagTermClick($event)" user-click="tagUserClick($event)"></div>
         </p>
         <br> {{post.author}} on {{post.date_Written}}
         <br>
         <div name="desktopSide">
            <button class="btn btn-primary btn-xs" type="submit" ng-click="update(post.id)" class="btn">
            <span class="glyphicon glyphicon-pencil"></span> Edit
            </button>
            <button class="btn btn-danger btn-xs" type="submit" ng-click="delete(post.id);deleteSummary(post.id);" class="btn btn-danger">
            <span class="glyphicon glyphicon-remove-circle"></span> Delete
            </button>
         </div>
         <div style="display:none;" name="mobileSide">
            <button class="btn btn-primary btn-xs" type="submit" ng-click="updateMob(post.id)" class="btn">
            <span class="glyphicon glyphicon-pencil"></span> Edit
            </button>
            <button class="btn btn-danger btn-xs" type="submit" ng-click="delete(post.id);deleteSummary(post.id);" class="btn btn-danger">
            <span class="glyphicon glyphicon-remove-circle"></span> Delete
            </button>
         </div>
         <div class="animate-repeat" ng-repeat="summarized in filterID(post.id)">
            <div class="animate-repeat" ng-repeat="new_post in getPost(summarized.child)">
               <button class="pull-right btn btn-default btn-xs" ng-click="reversePostState(new_post.id, new_post.name, new_post.author)">
               <span id="{{new_post.author}}" class="glyphicon glyphicon-plus"></span>
               </button>
               <div class="well ng-scope">
                  <h4>
                     {{new_post.name}}
                     <div id="{{new_post.name}}" style="display:inline;"> - {{new_post.author}}</div>
                     &emsp;&emsp; <span ng-if="new_post.summary==1" class="animate-if"><button class="btn btn-xs disabled"><span class="glyphicon glyphicon-star-empty"></span></button></span>
                     <a class="pull-right" ng-click="changeElemOnClick('id_search');changeid(new_post.id);">{{new_post.id}}</a>
                  </h4>
                  <div id="{{new_post.id}}" style="display:none;">
                     {{new_post.text}}
                     <br> {{new_post.author}} 
                     on {{new_post.date_Written}}
                     <br>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </li>
   <center ng-if="checkForPosts()">
      <button class="btn btn-default" ng-click="incrementLimit()">
      <span class="glyphicon glyphicon-arrow-down"></span>Show More Posts
      </button>
   </center>
</div>

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

Issue accessing PDF element within iFrame

I'm attempting to search for specific words within a PDF using a textbox on a webpage. I've embedded the PDF within an iframe, but unfortunately it's not functioning as expected. This code works fine with regular text, but when searching for ...

Adjust the height automatically in extjs hbox layout with this quick guide

When I try to dynamically set data in this layout, the layout doesn't resize properly and the final result looks like this. This is the code I'm currently using: win = Ext.create('widget.window', { title: 'Layout Window&apo ...

Add the item to the array only if it is not already included

After searching around, I have been unable to find a solution to my problem. My goal is to add an object to an array only if it is unique. We have a large list of data that we iterate through to extract the necessary information (for a drop-down box). Onc ...

Node 18 is having trouble locating NPM and is unable to locate the module './es6/validate-engines.js'

Previously, I attempted to install Node.js without any issues. However, this time around, I am encountering difficulties accessing the npm package. While I can successfully retrieve the version of Node.js after installation, attempting to check npm -v or w ...

Execute a function within the ajax success callback

I have crafted a code snippet that scans through all images within a specified div and assigns classes based on their sizes. Currently, this functionality is set to run when the document loads, and it works flawlessly upon initial page load. However, I a ...

Tips for styling tooltips in rc-slider

I am currently using the react library rc-slider and I am looking to add a tooltip feature to display the current value. I found guidance on how to do this from a post on the rc-slider GitHub page. However, I encountered an issue where my slider position b ...

How to emphasize the anchor tag chosen within Angularjs by utilizing ng-repeat

After gathering some data, I have successfully bound it to anchor tags using ng-repeat. <table style="width: 60%"> <tr> <td style="text-align: center" ng-repeat="displayyears in displayYears"> ...

Why is the Material Ui code functioning flawlessly in Codepen but not in VSCODE?

In my ReactJS project, I am using Material-UI to create "Material Tabs". The code works fine in SANDBOX but not in my VS CODE. What could be the issue? I have checked that Node is installed and all dependencies versions from NPM are up to date. I also tri ...

When working with Angular1+ ES6 and using controller as a class, the utilization of Dependency Injections may be ambiguous within controller functions

I recently started using ES6 class for defining my controller, and here is the syntax I am using: export class SearchBarController { constructor($log) { 'ngInject'; $log.debug("Hello"); } textTyped($log){ $ ...

When making a POST request using formData through AJAX, the $_POST variable remains empty

Below is the form: <form id="complaintForm" enctype="multipart/form-data" method="POST"> <input type="number" id="isComplaintForm" value="1" hidden> <label for="fname&q ...

Obtaining the Time Zone from an Area Code Using JavaScript

Can a Script in JavaScript Determine the Time Zone Based on Area Code? I possess the Area Codes of the User. ...

Using jQuery to create a drop-down menu

I currently have a table filled with data. Whenever a user clicks on a cell within a specific column, I would like it to transform into a select dropdown menu. This dropdown menu will allow the user to choose a category for that particular row. The selecte ...

Display the item request form whenever a selection of an unidentified item is made using select2

I want to implement select2 for a company search feature. In case the desired company is not available in the existing dataset, I need to provide an option for users to request adding the company data. This is the HTML code: <head> <link href=& ...

Executing a function from a dynamically generated element in AngularJS

I'm currently working on a custom query builder in AngularJS by modifying the angular-query-builder plugin. Here is a snippet of the code structure relevant to the context: base.html <query-builder group="filter.group"></query-builder> ...

Using AJAX to select data within Opencart and the "add to cart" button

As I delved into learning opencart development recently, I stumbled upon an intriguing discovery. It got me thinking about the "add to cart" functionality in the product info page, which uses Ajax. Below is a snippet of the JavaScript code: $('#butto ...

Video margins within a webview

After numerous attempts to embed a YouTube video in a WebView, I'm still struggling with a persistent small margin on the right side of the video. I've researched similar issues and attempted to address it through JavaScript adjustments without ...

What is the best way to present JSON data retrieved from an API on different pages using Next.js?

I am currently working on two pages that are connected: one is an API page called secured.js (where user session data is processed) and the other is a normal page also named secured.js (which displays the processed content from the API page). This is the ...

Dynamic change in the mutation observer is not causing the callback to trigger

I have created a nested structure with two <div> elements. I am monitoring changes in the width of the inner <div>, which is set to width:auto;. Despite adjusting the width of the parent <div>, the mutation observer callback doesn't ...

Retrieve the HTML contents of a cell that contains a checkbox with the value of "jquery"

Here is an example of a table row: <tr> <td><input type='checkbox' name='post[]' value="1"></td> <td>08-Apr-2014</td> <td>injj team</td> <td>merchant.testyy.com</ ...

Display all months on mobile screen using Mui DesktopDatePicker

Looking for a Better Date Range Picker I've been working on a project that requires a date range picker, and I opted to use the Mui date range picker. While it works well on desktop, I encountered an issue with mobile view where only one month is sho ...