I'm new to firebase, and I'm trying to add a Date Of Birth field to a form and save it to Firebase.
The input field in the form looks like this:
<label for="birthdate">Date of Birth</label>
<input type="date" id="birthdate" name="birthdate"
ng-model="user.birthdate" ng-required="true" placeholder="Last Name">
<p class="error validationerror"
ng-show="myform.birthdate.$invalid && myform.birthdate.$touched">
Birthdate is required</p>
Following a lynda.com tutorial, a working register function was created like this:
register : function(user) {
return simpleLogin.$createUser(user.email, user.password)
.then(function(regUser){
var ref = new Firebase(FIREBASE_URL + 'users');
var firebaseUsers = $firebase(ref);
var userInfo = {
date: Firebase.ServerValue.TIMESTAMP,
regUser: regUser.uid,
firstname: user.firstname,
lastname: user.lastname,
email: user.email
}
firebaseUsers.$set(regUser.uid, userInfo);
}); //add user
}, //register
I tried to simply add another birthdate: user.birthdate
key:value pair to the end after email: user.email but that didn't work.
register : function(user) {
return simpleLogin.$createUser(user.email, user.password)
.then(function(regUser){
var ref = new Firebase(FIREBASE_URL + 'users');
var firebaseUsers = $firebase(ref);
var userInfo = {
date: Firebase.ServerValue.TIMESTAMP,
regUser: regUser.uid,
firstname: user.firstname,
lastname: user.lastname,
email: user.email,
birthdate: user.birthdate
}
firebaseUsers.$set(regUser.uid, userInfo);
}); //add user
}, //register
Nothing gets added to firebase for the birthdate.
If I do console.log("user.birthdate: "+ user.birthdate);
right after var userInfo I can see the date that was chosen in the date picker... so I know its getting from the form into that register function.
I'm guessing that simpleLogin can only have firstname, lastname, and email?
A few helpful notes:
new Firebase(.../users
) is writing to Firebase, not the authentication service, and you can write any arbitrary data of your choosing there. However, check the type of the birthdate that you're writing. Firebase leaf values can be of type string
, number
, boolean
, or null
- but it is likely that your datepicker might be returning an Object
that just happens to toString()
correctly.