I have an HTML page with a form and a series of input fields and a carousel. At the bottom of the form is a button until Add another quote . Essentially a copy of the input fields above (total class="quote" ).
HTML:
<form name="myForm"> <div class="quote"> <p>Enter the fields below</p> <input type="text" ng-model="'firstname'+{{$index}}" /> <input type="text" ng-model="'surname'+{{$index}}" /> <input type="text" ng-model="'postcode'+{{$index}}" /> <input type="text" ng-model="'productid'+{{$index}}" /> <input type="text" ng-model="'price'+{{$index}}" /> <div class="carousel"> <img src="/assets/img/chair.jpg" alt="" /> <img src="/assets/img/spoon.jpg" alt="" /> <img src="/assets/img/table.jpg" alt="" /> <img src="/assets/img/tap.jpg" alt="" /> </div> <button class="add-another" ng-click="addAnother()">Add another quote</button> </div> </form>
What I'm trying to achieve is that when add-another pressed, paste a copy of class = "quote", where {{$ index}} also increases when clicked. The idea is to allow unlimited addition of lines ... Thus, the result will look like this:
<form name="myForm"> // First quote //////////////// <div class="quote"> <p>Enter the fields below</p> <input type="text" ng-model="'firstname'+{{$index}}" /> <input type="text" ng-model="'surname'+{{$index}}" /> <input type="text" ng-model="'postcode'+{{$index}}" /> <input type="text" ng-model="'productid'+{{$index}}" /> <input type="text" ng-model="'price'+{{$index}}" /> <div class="carousel"> <img src="/assets/img/chair.jpg" alt="" /> <img src="/assets/img/spoon.jpg" alt="" /> <img src="/assets/img/table.jpg" alt="" /> <img src="/assets/img/tap.jpg" alt="" /> </div> <button class="add-another" ng-click="addAnother()">Add another quote</button> </div> // Second quote //////////////// <div class="quote"> <p>Enter the fields below</p> <input type="text" ng-model="'firstname'+{{$index}}" /> <input type="text" ng-model="'surname'+{{$index}}" /> <input type="text" ng-model="'postcode'+{{$index}}" /> <input type="text" ng-model="'productid'+{{$index}}" /> <input type="text" ng-model="'price'+{{$index}}" /> <div class="carousel"> <img src="/assets/img/chair.jpg" alt="" /> <img src="/assets/img/spoon.jpg" alt="" /> <img src="/assets/img/table.jpg" alt="" /> <img src="/assets/img/tap.jpg" alt="" /> </div> <button class="add-another" ng-click="addAnother()">Add another quote</button> </div> // Third quote //////////////// // Fourth quote //////////////// // Fifth quote //////////////// </form>
Here's a very quick attempt with a plunker: http://plnkr.co/edit/bl1BMkLbeT2tr907lJYK?p=preview
Note that the Add another quote button does not work, click Add new quote at the top to insert new lines
I would really like to use the jQuery hide / show animation when rows are added / removed.
Although with a lot of mistakes!
javascript jquery html angularjs angularjs-directive
Oam psy
source share