Hi Kasper Welcome ;-)
When you are using form validation on an input, the model valid is only present when the input is valid. This may explain some of the behaviour that you are seeing. I put together this plnkr <http://plnkr.co/edit/Uxfybo?p=preview> for you to help explain this concept. Note that if you have a 8 digits in the second input, and then add a number - the model value is cleared. There is a good article on angular forms here that may answer some of your other questions. If not, let us know: http://www.yearofmoo.com/2014/09/taming-forms-in-angularjs-1-3.html Regards Justin On Friday, October 10, 2014 1:43:47 PM UTC+2, Kasper Gantzhorn wrote: > > Hi everyone, > I'm pretty new to Angular, so bear with me. > I have an input field (Company) where the user can write a company name, > and as the user types (change()) I make a $http look-up in an VATapi to > find the corresponding VAT number (8 characters). > When I find the right number I would like to update another input field > (VATnr.) with this value. The problem is, that when I put > > ng-minlength=8 ng-maxlength=8 > > > on the VATnr. input field the number is not updated in the (VATnr.) input > field. I've also tried > > ng-minlength="8" ng-maxlength="8" > > > > This is the code > //THE TWO INPUT FIELDS > <input type="text" name="company" placeholder="Indtast firmanavn" ng-model > ="user.company" ng-change="checkCVR()" ng-keydown="cvrKeyDown($event)" > required> > > <input type="text" name="cvr" placeholder="Indtast virksomhedens CVR.nr." > ng-model="user.cvr" ng-minlength=8 ng-maxlength=8 integer required> > > > > > //THE CONTROLLER > $scope.checkCVR = function() > { > > $http.jsonp('http://cvrapi.dk/api?callback=JSON_CALLBACK&search=' + > $scope.user.company + '&country=dk') > .success(function(data, status, headers, config) > { > $scope.compnay_name = data.name; > $scope.compnay_vat = data.vat; > > > }) > } > > > > $scope.cvrKeyDown = function($event) > { > if($event.keyCode == 13) > { > $event.preventDefault(); > $scope.user.cvr = $scope.compnay_vat; > } > > > } > > > $scope.updateCVRvat = function() > { > $scope.user.cvr = $scope.compnay_vat; > } > > > > Also, I would like to make the CVRnr input field only validate, when the > user types in numbers. I cannot use the type="number" attribute. > > > Thanks guys. > Kasper > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
