[solved] Issues with ReactiveVar & Blaze

Please I have been trying my hands on some various basic tasks on meteor and i cant seem to find a solution to this one.

/*****************************************************************************/
/* Signup: Event Handlers */
/*****************************************************************************/

import naijaNumber from 'naija-phone-number';
Template.Signup.events({
    // "keyup input[name=name], keypress input[name=name], change input[name=name]": function(e,tmpl){
    //     let value = e.currentTarget.value;
    //     console.log('name',value)
    //
    // },
    // "keyup input[name=password], keypress input[name=password], change input[name=password]": function(e,tmpl){
    //     let value = e.currentTarget.value;
    //     let User = tmpl.setUser();
    //     console.log('password',value)
    //     User.password = value;
    //     tmpl.setUser(User, true);
    // },
    "keyup .phone-input, keypress .phone-input, change .phone-input": function(e,tmpl){
        let value = e.currentTarget.value;
        let user = getUser();
        if (value && value.trim().length > 0) {
            user.phone = value
        } else {
            delete user.phone ;
        }
        
        Template.instance().user.set(user);
    },
    
    "click .create-account-button": function (event, template) {
        event.preventDefault();
     

        //trim
        let User = Template.instance().user.get();

        console.log('user',User)


    }
});

/*****************************************************************************/
/* Signup: Helpers */
/*****************************************************************************/
Template.Signup.helpers({
});

/*****************************************************************************/
/* Signup: Lifecycle Hooks */
/*****************************************************************************/
Template.Signup.onCreated(function () {

    let instance = this;
    instance.user = new ReactiveVar();

});

Template.Signup.onRendered(function () {
});

Template.Signup.onDestroyed(function () {
});

let getUser = () => {
    return Template.instance().user.get();
}

i get this error

signup.js:23 Uncaught TypeError: Cannot set property 'phone' of undefined
    at Object.keyup .phone-input, keypress .phone-input, change .phone-input (signup.js:23)
    at blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3818
    at Function.Template._withTemplateInstanceFunc (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3769)
    at Blaze.View.<anonymous> (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3817)
    at blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:2617
    at Object.Blaze._withCurrentView (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:2271)
    at Blaze._DOMRange.<anonymous> (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:2616)
    at HTMLInputElement.<anonymous> (blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:863)
    at HTMLDivElement.dispatch (jquery.js?hash=4243d4a77640caf927d698e462964f41b6e712f8:5282)
    at HTMLDivElement.elemData.handle (jquery.js?hash=4243d4a77640caf927d698e462964f41b6e712f8:4934)

a very simple sign up page here , i want to use Reactivevar to store the data into the template for global access but it doesn’t seem to work

        let user = getUser();
        if (value && value.trim().length > 0) {
            user.phone = value

Where is getUser(); coming from?

1 Like

it is coming from the ast bottom lin where i defined it.

I have been able to resolve this issue by reverting my reactivevar from the latest to reactive-var@1.0.11

by running
meteor remove reactive-var
then
meteor add reactive-var@1.0.11

Thank you.