"Challenges Encountered When Using Angular in Conjunction with Bootstrap

Is there a way to apply ng-disable on a Bootstrap Modal Dialog when the form in a Partial View displayed in the Modal is Invalid?

Working with Asp.net MVC, I am facing an issue where I include a Partial View in a Modal form. The form should display details for editing or show a blank form for adding a new record upon clicking an item. Using Bootstrap Modal (data-target) works perfectly for opening the dialog. However, my ng-click function for saving changes prevents me from closing the dialog with data-dismiss as the button is in the partial view. If I move the save button to the parent, ng-disable stops working for form validation. Switching to Angular ui-Modal seemed like a solution, but it only works for displaying existing records and fails to open the modal for a new record. This problem has consumed hours of my time.

To sum up, I need help either with closing the Bootstrap Modal from my Angular Controller using ng-click or figuring out how to display the empty form using Angular ui-Modal.

Below is the code snippet for the modal in my cshtml View:

<div class="container">
            <!-- Modal -->
            <div class="modal fade" id="addNewComment" role="dialog">
                <div class="modal-dialog modal-lg">
                    <!-- Modal content-->
                    <div class="modal-content">
                        <div class="modal-header" style="background-color:#003A5D; color:white">
                            <h4 class="modal-title">Comment View</h4>
                        </div>
                        <div style="background-color:red;color:white;margin-top:-3px">Questionnaire is Incomplete</div>
                        <div class="modal-body">
                            @Html.Partial("_AddNewComment")
                        </div>
                        <div class="modal-footer">

                        </div>
                    </div>
                </div>
            </div>

        </div>

This is the rendered Partial View:

<div class="panel panel-primary">
    <div class="panel-heading">Add New Comment</div>
    <div class="panel-body" ng-repeat="cm in selection.comment">
        <form name="CommentForm">
        <table style="width:100%; border:none">
           <!-- Form Fields -->
        </table>
        Long Comment (shown as Pop-up on the Contractor's homepage)<br />
        <div style="font-size:8px">Max 2000 characters</div><br />
        <textarea style="width:100%;height:200px" ng-model="cm.vchLongComment" required>
            {{cm.vchLongComment}}
        </textarea>
        <br />
           <!-- Buttons -->
        </form>


    </div>
</div>

Angular Controller Code:

 $scope.clickTest = function (comment) {
        debugger;
        $scope.selection.comment.splice(comment);


    };
    $scope.ShowDetails = function (comment) {
        debugger;
        if (comment == undefined)
        {
            comment = [
                {
                    id: 0,
                    vchShortComment: 'please add short comment',
                    vchLongComment: 'please add long comment'
                }
            ]
        }
        $scope.selection.comment.push(comment);
         //modalInstance = $modal.open({
        //    templateUrl: 'addNewComment',
        //    controller: ModalInstanceCtrl
        // });

    };

    var ModalInstanceCtrl = function ($scope, $modalInstance) {


        $scope.ok = function () {
            $modalInstance.close($scope.selected.item);
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };

    };

Answer №1

All of my issues were resolved by enclosing the entire Modal in an additional set of tags. Placing the buttons in the modal-footer allowed for the proper functioning of data-target, data-dismiss, and form validation. Here is the UPDATED HTML code for the Modal. Hopefully, this solution can assist someone else!

 <form name="CommentForm">
    <div class="modal fade" id="addNewComment" role="dialog">
        <div class="modal-dialog modal-lg">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header" style="background-color:#003A5D; color:white">
                    <h4 class="modal-title">Comment View</h4>
                </div>
                <div style="background-color:red;color:white;margin-top:-3px">Questionnaire is Incomplete</div>
                <div class="modal-body">
                    @Html.Partial("_AddNewComment")
                </div>
                <div class="modal-footer">
                    <span style="float:left"><button type="button" class="btn btn-danger">Delete Comment</button>&nbsp;&nbsp;<button type="button" class="btn btn-primary">Archive</button></span><span style="float:right"><button type="button" style="background-color:#adabab; color:White; border-color:#adabab" data-dismiss="modal" class="btn btn-default" ng-click="clickTest()">Cancel</button>&nbsp;&nbsp;<button type="button" class="btn btn-primary" data-dismiss="modal" ng-disabled="CommentForm.$invalid" ng-click="saveComment()">Save</button></span>

                </div>
            </div>
        </div>
    </div>
</form>

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

An effective way to incorporate internal scripts into a view within the Play Framework

Is there a preferred method for including internal JavaScript code in a Play Framework view using script tags? ...

Ways to alter a PHP variable with each AJAX request

Utilizing AJAX to dynamically add more content to an image gallery. I'm passing a PHP variable to dictate the current page number and other necessary data. Each time new data is fetched via AJAX, I want to increment the page variable by one to fetch ...

Angular application with Material Design integration

I've been struggling to implement material design into my angular app, but I'm facing some challenges. After installing material design and adding all the necessary modules to the app.moduel.ts file, the components are not displaying correctly. ...

Looking to clean up unnecessary <b></b> tags from my Wordpress website - how can I do this?

One of my sites is located at . When inspecting the source code through the browser, I noticed the presence of empty tags. Does anyone know why these empty tags are being generated and how they can be removed? I have thoroughly searched through all files ...

AngularJS JSON Array

I have an array containing multiple objects in JSON, as well as a select element that contains an array. Depending on the selection made in the first array, another select box will be dynamically loaded right below it. HTML Code <div class="list"> ...

How to dynamically update ng-repeat values using AngularJS and PHP

I'm facing an issue in my code where I am using ng-repeat, but only the last value gets updated when I try to update "frais" of all values displayed by ng-repeat. Can someone please help me figure out how to update all values? file.html <ion-cont ...

Proper method for verifying line-clamp in a Vue component

I came across a question that aligns perfectly with my current task - determining if text is truncated or not. The query can be found here: How can I check whether line-clamp is enabled?. It seems like my approach may not be accurate, so any guidance on ho ...

Incorporating a JSON array response into an angular range slider

I received a dynamic json response that looks like this. I am looking to incorporate these details into a range slider. The maximum value of the slider should increase dynamically as new elements are added to the array. "time": [ "2018-05-24T06:30 ...

Ways to populate the second nested array with new values without overwriting existing ones

I am encountering the following issue: this.logs = {}; this.logs[1] = resp; In my initial array, I have the result shown in the image below: https://i.sstatic.net/RScSm.png However, when I try to add a second level array with another array like this: th ...

I am receiving the same URL for multiple files stored on Firebase Storage

After attempting to upload multiple files to Firebase Storage and retrieve the download URL for each one, I encountered an issue where all files were successfully uploaded but only the URL for the last file was retrieved. The following code snippet shows ...

Verifying the functionality of a custom directive in Angular 2 (Ionic 2) through unit

In my ionic application, I developed a custom directive specifically for text masking, aimed at formatting phone numbers within input fields. The core functionality of this directive revolves around utilizing ngControl to facilitate the retrieval and assig ...

Issue duplicating DIV elements using jQuery's clone() method causes button duplication error

Just starting out with programming, so my code might not be perfect. I'm encountering an issue when I click a button in the HTML (Fiddle) $(document).ready(function() { $("button").click(function() { $(".groupcontainer").clone().appendTo(".grou ...

Checking for the presence of a specific function in a file using unit testing

I am curious if there is a possible way to utilize mocha and chai in order to test for the presence of a specific piece of code, such as a function like this: myfunction(arg1) { ...... } If the code has been implemented, then the test should return t ...

Weak Password Alert

After spending hours writing code for form validation and password strength checking, I encountered a roadblock. The form validates successfully, but the password strength indicator is not updating as expected. Despite double-checking the logic in my code ...

Exploring THREE.js with VIVE Headset (JavaScript/Browser/WebGL in the Steam Universe)

Can you use THREE.js JavaScript to create experiences for the VIVE headset? Is it feasible to display a Chrome web browser in fullscreen mode on the VIVE? One challenge I foresee is tapping into the data from the controller paddles. How can this be achie ...

What is the best way to change the heading text and color in React based on the time of day when calling a function?

I want to dynamically change the text and color of my h1 heading based on the time of day. I'm encountering an error with my current code: "Cannot set property 'innerText' of null". I've tried to figure out how to incorpor ...

Arrange ASP MVC website

I'm a beginner in ASP MVC and I'm currently working on creating a website that requires a header, footer, menu, and main content section. Can anyone offer advice on the best approach for implementing these elements? Should I use partial views or ...

"Exploring the power of JQuery in adding new elements and accessing the newly appended

I have a code that appends some HTML to a div using JQuery like this: $("#divId").append("<div class='click' data-id='id'></div>"); and I want to access the appended div by clicking on it like so: $(".click").click(functi ...

How to ensure unique results when using DFS for Combination Sum?

I am currently tackling the challenge of solving LeetCode #49 Combination Sum. The objective here is to identify all the distinct combinations that add up to the specified target. While it's relatively straightforward to find permutations that result ...

Choose a start date for the date picker that is either one day from today

On my AngularJS website, it launches on January 1, 2019. I have a datepicker that I want to restrict from picking dates before the launch date. I achieved this by using the following code: <div class="input-group date date-picker" data-date-format="dd ...