When attempting to add a "pick file and delete button" feature upon clicking the add button, a problem with aligning the bootstrap panel body has been

I am currently working on adding a "choose file button and remove button" alongside another add button within a bootstrap panel body. While the add button is functioning correctly, I am encountering alignment issues with the newly added row.

Here is the current layout using Bootstrap:

The problem lies in the body alignment of the panel:

Any suggestions on how to rectify this issue?

Please see below for the code snippet I am working with.

<!doctype html>
<html>

<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.9/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.9/angular-resource.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.9/angular-route.min.js">
  </script>
  <script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>
  <script src="https://cdn.firebase.com/libs/angularfire/0.9.0/angularfire.min.js"></script>
  <script src="js/app.js"></script>
  <script src="js/uploadAttachementFiles.controller.js"></script>
  <script src="js/uploadAttachementComponent.js"></script>
  <link rel="stylesheet" href="css/uploadAttachementfiles.css">
</head>

<body ng-app="App" ng-controller="UploadController as vm">


  <div class="container">
    <div class="row">
      <div class="form-group row">
        <label for="desc" class="col-xs-3 col-md-3 col-form-label">Description:</label>
        <div class="col-xs-8 col-md-5">
          <textarea class="col-xs-8 col-md-9" rows="3" cols="5" maxlength="255" id="desc" style="resize: none;"></textarea>
        </div>
      </div>

      <div class="container">
        <div class="form-group  row ">
          <label for="uplodedFiles" class="col-xs-3 col-md-3 col-form-label">Uploded Files:*</label>
          <div class="panel panel-default col-xs-9 col-md-8">
            <div class="panel-heading">Location</div>
            <div class="panel-body ">
              <div ng-repeat="file in vm.files">
                <button type="button" class="btn col-xs-1 col-form-label" ng-hide="myValue" ng-click="Remove($index)">
                                  <span class="glyphicon glyphicon-remove-sign"></span>
                                </button>
                <input type="file" value="{{vm.Name}}" id="fg" />
              </div>
            </div>
            <div class="form-group ">
              <span class="glyphicon glyphicon-plus-sign" ng-click="Add()"></span>
              <input type="button" ng-click="Add()" value="Add" ng-model="Name">
            </div>
          </div>
        </div>
      </div>
      </form>
    </div>
  </div>
  <script>
    var App = angular.module('App', []);
    App.controller('UploadController', ['$scope', function($scope, $window) {
      var file = {};
      $scope.vm.files = [file

      ];
      $scope.Add = function() {
        //Add new item to Array
        var file = {};
        file.Name = $scope.Name;
        $scope.vm.files.push(file);
        //Clear Text boxes
        $scope.Name = "";
        console.log(file);
      };
      $scope.Remove = function(index) {
        //Find the record From Array Using index
        {
          //Remove Item from Array using index
          $scope.vm.files.splice(index, 1);
          console.log(index, 1);
        }
      }
    }]);
  </script>
</body>

</html>

Answer №1

Like others have mentioned previously, it's important to maintain code sanity.

The issue you are experiencing is due to adding

<div class="panel panel-default col-xs-9 col-md-8">
, and combining grid-column(col-xs-9 col-md-8) classes with the panel. To resolve this problem, move the column-related classes to a separate div, and everything should work correctly.

Feel free to refer to the snippet below for a working example:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="container">
  <div class="form-group row">
    <label for="desc" class="col-xs-4 col-md-3 col-form-label">Description:</label>
    <div class="col-xs-8 col-md-9">
      <textarea class="btn-block" rows="3" cols="5" maxlength="255" id="desc" style="resize: none;"></textarea>
    </div>
  </div>
  <div class="form-group row">
    <label for="uplodedFiles" class="col-xs-4 col-md-3 col-form-label">Uploaded Files:*</label>
    <div class="col-xs-8 col-md-9">
      <div class="panel panel-default">
        <div class="panel-heading">Location</div>
        <div class="panel-body">
          <div ng-repeat="file in vm.files">
            <div class="clearfix">
              <button type="button" class="btn btn-xs btn-danger pull-left" style="margin-right: 10px" ng-hide="myValue" ng-click="Remove($index)">
                <span class="glyphicon glyphicon-remove-sign"></span>
              </button>
              <input type="file" value="{{vm.Name}}" id="fg" class="pull-left" />
            </div>
            <hr />
          </div>
          <div class="form-group">
            <span class="glyphicon glyphicon-plus-sign" ng-click="Add()"></span>
            <input type="button" ng-click="Add()" value="Add" ng-model="Name" />
          </div>
        </div>
      </div>
    </div>
  </div>
</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

implement adding a division element to the DOM using the append

I am facing an issue with this particular code. The intended functionality is to create multiple divs in a loop, but it seems to be dysfunctional at the moment. Upon clicking, only one div appears and subsequent clicks don't trigger any response. < ...

Filled with information provided on the form page

After completing the form and submitting it, I noticed that when I went back to fill out another request, all the fields were already populated with my previous data. How can I reset the form page to have empty values each time? Appreciate your help ...

How come my RXJS next method is being invoked before the $digest cycle is completed, and what is the best way to wait for it to

Below is a code snippet written in Coffeescript: beforeEach "We should see the list changed event", (done) -> constructorSubscription = importList.onListChanged().subscribe -> # Expects constructorSubscription.unsubscribe() ...

Are there any methods to create a circular z-index?

Is there a way in CSS to arrange #element-one above #element-two, then #element-two above #element-three, and finally #element-three above #element-one? Are there alternative methods to achieve this layout? ...

What could be causing a template value in my AngularJS/Ionic Framework code to not be replaced properly?

Recently, I've been exploring the world of Ionic Framework with Angular by my side. However, I've hit a bit of a roadblock. My goal is to set up tabs at the bottom of my application using a model definition. Here's what I've tried so ...

Can we implement add_image_size along with get_theme_file_uri?

I have a custom field in ACF for images linked to my custom post type. In case no image is selected, it should default to an image from the media library. If the check for get_field('box_image') returns empty or null, I want to use a default ima ...

Angular is known for its ability to beautifully format HTML text within

As a newcomer to Angular, I am currently working on developing a blog website. One of the features I have included is a tinymce editor for users to write their content with predefined formatting options. https://i.sstatic.net/rA8lJ.png The user-generated ...

Using an iframe with THREE.js and WebGlRenderer can result in the domElement's getBoundingClientRect method returning 0

I encountered an issue with my code: ... renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); renderer.setSize(WIDTH, HEIGHT); ... controls = new TrackballControls(camera, renderer.domElement); Strange behavior occurs when I r ...

Trouble with AngularJS: View not refreshing

Implementing infinite-scrolling in AngularJs involves a function that is triggered after a successful AJAX call. This call occurs when: The user reaches the end of the screen. The user applies filters and presses the "Search" button. If it's the fi ...

Generate a new web component using JavaScript

My HTML table looks like this: <table id = "rpttable" name = "rpttable"> <thead> Column Headers here... </thead> <tbody id = "rptbody" name = "rptbody"> data here <3 .... </tbody> </table> And in my ...

several form pop-ups within a single webpage

I require assistance with Javascript. My goal is to showcase a dynamic name inside the modal using multiple forms. Currently, I have this setup where it displays "Are you sure you want to delete bob?" when I want it to show "tom" if I click on the delete t ...

Encountered an error with an unregistered controller in the same application while using two

Let me set the scene: Here are snippets from both the JS file main.js and the HTML file index.html: angular.module("myApp", []); angular.module("myApp", []).controller("postController", function($scope) { $scope.buttonName = "Post"; }) angular.mod ...

What is the best way to extract data from an object and save it within a $scope variable?

I was previously assisted with an array and now I am trying to extract the values for monthlyIncome, savePercent, and years and then store them in $scope.monthlyIncome, $scope.savePercent, and $scope.years. Can anyone spot where I may be making a mistake? ...

locate the following div using an accordion view

Progress: https://jsfiddle.net/zigzag/jstuq9ok/4/ There are various methods to achieve this, but one approach is by using a CSS class called sub to hide a 'nested' div and then using jQuery to toggle the Glyphicon while displaying the 'nest ...

Ways to align text vertically within a div using Bootstrap 4

I'm having trouble centering text in a bootstrap column. I've attempted various methods like "align-items-center", margin auto, and display: table but haven't been successful. I've also searched through similar questions on this platfor ...

Developing New Arrays from JSON Responses using AngularJS

I have a function linked to the factory for controlling: fac.GetDailyCountersList = function () { return $http.get('/Data/GetDailyCountersList') } Within the controller, this is how the function is invoked: $scope.DailyCounters = null; Dai ...

Expansion issue with Bootstrap panel

I am currently using Bootstrap 3 for the development of a social networking site. The issue I'm encountering involves displaying comments within a panel footer on toggle. However, the comments are extending beyond the footer area. Can anyone provide g ...

Can the orientation of the card reveal be customized in Materializecss?

Exploring the card-reveal feature in the materializecss framework on this page: https://codepen.io/JP_juniordeveloperaki/pen/YXRyvZ with official documentation located at: In my project, I've rearranged the <div class="card-content"> to display ...

Close the gap in the CSS for the image tag

I am facing an issue. Whenever I include an img Tag in my HTML File, there is a Gap around the tag. It is neither margin nor padding. I wonder what it could be? Could someone please assist me in removing the gap with CSS? <img src="../images/modules/ ...

Angular 2 is throwing an error message stating that Foods.filter is not recognized as a function

Whenever I attempt to delete multiple items by selecting checkboxes, I encounter the error Foods.filter is not a function in my console. Strangely, this error only occurs when I include a pipe in the HTML table. Without the pipe, everything functions as ex ...