javascript - See if number is in Firebase -
so have form registers users,
<form class="" ng-submit="vm.passwordregister()"> <div class="panel panel-default"> <div class="panel-heading"> register </div> <div class="panel-body"> <div class="form-group"> <input type="text" ng-model="vm.number" class="form-control" placeholder="client number" ng-blur="vm.numbercheck()"/> </div> <div class="form-group"> <input type="text" ng-model="vm.name" class="form-control" placeholder="your name" /> </div> <div class="form-group"> <input type="text" ng-model="vm.email" class="form-control" placeholder="e-mail address" /> </div> <div class="form-group"> <input type="password" ng-model="vm.password" class="form-control" placeholder="password" /> </div> <div class="form-group"> <input type="password" ng-model="vm.secret" class="form-control" placeholder="account secret" /> </div> </div> <div class="panel-footer clearfix"> <button type="submit" class="btn btn-primary pull-right" ng-if="accountopen.$value">register <i class="fa fa-arrow-right"></i></button> <button type="submit" class="btn btn-primary pull-right" ng-if="!accountopen.$value" disabled>register disabled</button> </div> </div> </form>
the user enters customer number @ beginning of form , secret @ end of form.
in end want sure of 2 things before creating user.
1. customer number exists in firebase 2. secret matches customer number entered
right i'm trying call function vm.numbercheck()
checks if customer number or number
exists , if returns snapshot or snap
user. mark field valid on html side , allow form submission.
my function looks following:
vm.numbercheck = function ($scope, $vm, $window) { ref.child('clientnumbers').startat(vm.number).endat(vm.number).once('value', function(snap) { console.log('accounts matching customer number', snap.val()); }); }
the way me data returned click in number field , blur without typing (provide empty query) if type in field if copied , pasted firebase returns null.
what doing wrong?
i created jsfiddle , added think of still won't run. here is: https://jsfiddle.net/05dds4v3/5/ connected test firebase application created.
i created working jsbin shows how detect existence of number in list: http://jsbin.com/pesimo/1/edit?js,output
the crucial function is:
function checkifnumberexists(number) { log('checking if '+number+' exists, may take moment'); ref.child('clientnumbers').child(number).once('value', function(snapshot) { log('got value, let\'s see if number exists'); if (snapshot.val() === null) { log('our number not yet exist, let\'s create it'); ref.child('clientnumbers').child(number).set(true, function(error) { if (error) { log('error creating number: '+error.tostring()); } else { log('number created, check if exists now\n'); } }); } else { log('yes, our number exists\n'); } }); }
note did not create angularjs nor angularfire nor jquery, solution focuses purely on detecting if specific child node exists. key in isolating problem (and 1 of steps in providing mcve). reducing problem core, either find cause of problem or make easy possible people (since need debug fewer technologies).
Comments
Post a Comment