I'm using the same form both creating and editing model, however, it cannot be edited if the file is not selected since ngf-select requires it
| <form class="form-horizontal" role="form" class="edit-user"> | |
| <div class="form-group"> | |
| <label for="name" class="col-md-2 control-label col-md-offset-2"> | |
| Pavadinimas | |
| </label> | |
| <div class="col-md-5"> | |
| <input type="text" name="name" class="form-control" placeholder="{{program.title}}" ng-model="program.title" value="{{program.title}}"> | |
| </div> | |
| <label for="id" class="col-md-2 control-label col-md-offset-2"> | |
| ID | |
| </label> | |
| <div class="col-md-5"> | |
| <input type="text" name="name" class="form-control" placeholder="{{program.title}}" ng-model="program.id"> | |
| </div> | |
| <div> | |
| <h4>Upload on file select</h4> | |
| <button type="file" ngf-select ng-model="file" | |
| accept="image/*" ngf-max-height="1000" ngf-max-size="1MB"> | |
| Select File</button> | |
| <br><br> | |
| File: | |
| <div style="font:smaller">{{f.name}} {{errFile.name}} {{errFile.$error}} {{errFile.$errorParam}} | |
| <span class="progress" ng-show="f.progress >= 0"> | |
| <div style="width:{{f.progress}}%" | |
| ng-bind="f.progress + '%'"></div> | |
| </span> | |
| </div> | |
| {{errorMsg}} | |
| </div> | |
| </div> | |
| </div> | |
| <div class="form-group" > | |
| <label | |
| for="description" | |
| class="col-md-2 control-label col-md-offset-2"> | |
| Aprašymas | |
| </label> | |
| <div class="col-md-5"> | |
| <textarea name="description" class="form-control" ng-model='program.description' placeholder="e.g. Flambé for 20 seconds"> | |
| </textarea> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <div class="col-md-offset-2 col-md-3"> | |
| <button class="btn btn-default" ng-click="cancel()"> Atšaukti</button> | |
| </div> | |
| <div class="col-md-4 text-right"> | |
| <button class="btn btn-success" | |
| ng-click="uploadFiles(file)">Submit</button> | |
| </div> | |
| </div> | |
| </section> |
| $scope.uploadFiles = function(file, errFiles) { | |
| if ($scope.program.id) { | |
| $scope.f = file; | |
| $scope.errFile = errFiles && errFiles[0]; | |
| if (file) { | |
| file.upload = Upload.upload({ | |
| url: '/programs/3.json', | |
| method: 'PUT', | |
| fields: {'program[title]': $scope.program.title, 'program[avatar]': $scope.program.file, 'program[description]': $scope.program.description, 'program[id]': $scope.program.id} | |
| }); | |
| file.upload.then(function (response) { | |
| $timeout(function () { | |
| file.result = response.data; | |
| }); | |
| }, function (response) { | |
| if (response.status > 0) | |
| $scope.errorMsg = response.status + ': ' + response.data; | |
| }, function (evt) { | |
| file.progress = Math.min(100, parseInt(100.0 * | |
| evt.loaded / evt.total)); | |
| }); | |
| } } return $location.path("/dashboard/programos/"); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment