Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70429

Form input fields initialization with values

$
0
0

@qoghij wrote:

I've got an input form which needs to be prefilled with data from the app. It's an edit Task form.
When I initialize the values in the controller the most of them work fine, but the checkbox which is initialized with a value that's true or false doesn't work correctly. I inserted alerts which tell me about the value when it is set, and they say that the checkbox should be checked, and the value is true, but then in the form the checkbox isn't set.
When I then save the Data it tells me, that the value which gets saved is true, even if the checkbox isn't set. When I then check the Checkbox and save the value again it tells me that the value is true again.
After thet I uncheck the checkbox and it says, that the Value is not true,
Here is my Code:
<ion-view view-title="{{title}}">
<ion-content class="padding">
<form ng-submit="save(et.id, et.title, et.remember, et.latencytime, et.lastdone)" novalidate ng-controller="TaskEditCtrl" name="form" id="form">
<input type="hidden" ng-model="et.id"><br>
Titel: <input ng-model="et.title"><br>
<input type="checkbox" ng-model="et.remember" id="remember">Erinnern</input>
Latenzzeit: <input ng-model="et.latencytime"><br>
<input type="hidden" ng-model="et.lastdone"><br>
</p>
<div class="padding">
<button type="submit" class="button button-positive">Save</button>
</div>
</form>
</ion-content>
</ion-view>

.controller('TaskEditCtrl', function($scope, $stateParams, $cordovaSQLite, Tasks) {
$scope.et=new Object();
if($stateParams.taskId==-1) {
$scope.et.id = -1;
$scope.et.title = 'neuer Task';
$scope.et.remember = false;
$scope.et.latencytime = 24;
$scope.et.lastdone = 'never';
}
else {
$scope.et.id = Tasks.getEditTask($stateParams.taskId).id;
$scope.et.title = Tasks.getEditTask($stateParams.taskId).title;
$scope.et.remember = Tasks.getEditTask($stateParams.taskId).remember;
document.getElementById('remember').value = Tasks.getEditTask($stateParams.taskId).remember;
document.getElementById('remember').checked = Tasks.getEditTask($stateParams.taskId).remember;
alert(Tasks.getEditTask($stateParams.taskId).remember);
if(Tasks.getEditTask($stateParams.taskId).remember)
{
alert('It should be checked!');
}
else
{
alert('It shouldn\'t be checked!');
}
$scope.et.latencytime = Tasks.getEditTask($stateParams.taskId).latencytime;
$scope.et.lastdone = Tasks.getEditTask($stateParams.taskId).lastdone;
}
$scope.save = function(id, title, remember, latencytime, lastdone) {
Tasks.saveTask(id, title, remember, latencytime, lastdone, $cordovaSQLite, $scope);
}
})

Any help will be greatly apreciated.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>