Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am repeating a form using ng-repeat. the repetition is to create a new form. I want to submit all forms data on single click. i am not able to find how I can assign multiple values in array.

Here is my form:

<div id="check" ng-repeat="screen in screens">
                   <input type="hidden" name="scrnid" ng-model="screen.scrnid" value="{{ screen.scrnid }}" />
            <label>Name:</label>
            <input type="text" ng-model="screen.bdayname" placeholder="Name" ng-required/>
            <label>Date:</label>
            <input type="date" ng-model="screen.bdaydate" placeholder="Date" ng-required/>
            <br/>
               </div>

               <button class="btn" type="submit" ng-click="newBirthday()">Save</button>
</div>
<div class="container">
        <input type="button" class="btn" ng-click="createScreen()" /><i class="icon-plus"></i>Add
</div>

and it is my controller

app.controller('main', function($scope){ 

    $scope.screens = [{scrnid: "1"}];
    $scope.scrnid = 1;
    $scope.createScreen = function()
    {
            $scope.screens.push({scrnid: "" + ($scope.screens.length + 1)});            
    };

    $scope.bdays = [];        
    // Create the function to push the data into the "bdays" array

    $scope.newBirthday = function(){        

        $scope.bdays.push($scope.screens.length);  // how to push mutiple records in array dynamically

        $scope.screen.bdayname = '';
        $scope.screen.bdaydate = '';
    };
});

help will be appreciated...

share|improve this question
    
assign multiple values in array, what are these multiple values? –  ta-run Mar 11 at 10:12
    
$scope.bdays.push() here in this array if i want to send multiple values i will do it like this: $scope.bdays.push([ {'name': 'name1'}, {'name': 'name2'} ]); this is angularjs way to do. But what should i do to insert the values from my html form that is repeated, into this array... –  trig_php Mar 11 at 10:21

1 Answer 1

I have edited the code to get the objects to be stored into the bday scope variable

var app=angular.module("birthdayToDo",[]);


app.controller('main', function($scope){ 

   $scope.screens = [{scrnid: "1"}];
  $scope.scrnid = 1;
    $scope.createScreen = function(){
            $scope.screens.push({scrnid: "" + ($scope.screens.length + 1)});  

            console.log($scope.screens);          
        };

        $scope.bdays = [];        


    $scope.newBirthday = function(){

        for(i=0;i<$scope.screens.length;i++){
            $scope.bdays.push($scope.screens[i])
        }
        console.log($scope.bdays);


    };


    $scope.remove=function(item){ 
      var index=$scope.bdays.indexOf(item)
      $scope.bdays.splice(index,1);     
    }



});
share|improve this answer
    
Here you have done it for single form . To pass single form values i can pass them easily. But if you have noticed i am repeating this form and now i want to submit all forms data . how will i manage it with form repetition... –  trig_php Mar 11 at 11:01
    
check this fiddle jsfiddle.net/9fqfh8ty here multiple forms are being used and a save action for each form, I have also editted the answer above , let me know if this solves your issue –  melwyn pawar Mar 11 at 12:06
    
Here you have three forms with three buttons setting up the target buttons value to fill in array. I want three forms with single buttons and adding all three records values in arrray. do u have any idea for that... –  trig_php Mar 11 at 13:06
    
you mean you have 3 forms but a single save button ? –  melwyn pawar Mar 11 at 13:34
    
yes and those three forms are created in ng-repeat means i am having single form which i am repeating n have single save button i want to save these forms on single click to database, and repeating of forms is dynamic . forms can be 3 or 4 or 5 .... –  trig_php Mar 11 at 18:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.