dimanche 19 avril 2015

Dynamic table with input fields inside the form AngularJS and Laravel

I am developing the application using Laravel and AngularJS. I have a dynamic table inside the form which will have the number of input fields based on the user selection. Number of rows in the table will be selected by user. my code is as below



quass.controller('newuploadctrl',[ '$scope', '$upload','$location', function ($scope, $upload, $routeParams, $location) {

$scope.newuploadsubmit = function() {

var files = $scope.files;

$scope.upload = $upload.upload({

url: 'newupload',
file: files[0],
fields: {'data':$scope.uploadform}

})

.success(function(data, status, headers, config) {

alert("Upload completed successfully");


});
}

$scope.qgGenerateSecTable = function(col_value){

var columns = [];
var col = {};

for(var i=1; i<=col_value;i++){

col = {};
col["title"] = "section"+i;
columns.push(col);

}

$scope.qg_sections = columns;
}


HTML



<div class="col-lg-3 field-name" style="padding-top:10px;">
<select class="form-control col-lg-3" ng-model="qg_no_section" ng-change="qgGenerateSecTable(qg_no_section)">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>

<table class="table table-bordered">
<thead>
<tr style="background-color: whitesmoke;">
<th></th>
<th ng-repeat="qg_sect in qg_sections">{{qg_sect.title}}</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Time</td>
<td ng-repeat="qg_sect in qg_sections">
<input type="text" class="form-control" ng-model="uploadform.section_time[qg_sect]"/>
</td>
<td><input type="text" class="form-control" ng-model="uploadform.qg_section_total_time[qg_sect]"/></td>
</tr>
<tr>
<td>Mark</td>
<td ng-repeat="qg_sect in qg_sections">
<input type="text" class="form-control" ng-model="uploadform.qg_section_mark[qg_sect]"/>
</td>
<td><input type="text" class="form-control" ng-model="uploadform.qg_section_total_mark[qg_sect]"/></td>
</tr>
</tbody>
</table>


Above html code present inside the form. I am not able to receive the table values with propery namespace or index at the server side in Laravel/php. I am not able to get the idea to how to name the models dynamically and get the values on form submission.


Aucun commentaire:

Enregistrer un commentaire