New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'value' of undefined in template function #251

Closed
jay7793 opened this Issue Oct 28, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@jay7793

jay7793 commented Oct 28, 2016

Hi everyone !!

I have a created typeahead template with the following configuration. but I can't access property in the item object. it error "Uncaught TypeError: Cannot read property 'value' of undefined" how I can I do it?

My template.

template: function (query, item) {
    var template =  '<span class="thumbnail"><img src="{{thumbnail}}"></span>' +
                  '<span class="detail">' +
                  '<span class="date">{{date}}</span>'+             
                  '<span class="title">{{title}}</span>' +
                  '<span class="meta">({{instructor}})</span>' +
                  '</span>'
      if (item.date) {
           template += '<span class="ribbon">Top Rated</span>';
      }
      return template;
},

In configuration above i have access to item.date but not work. If i console.log(item) it output object data in the console. Like this.

Image of Yaktocat

@running-coder

This comment has been minimized.

Owner

running-coder commented Oct 28, 2016

Hey @Natdanai-Wongtib , your template seems right, would it be possible to use the unminified file and give me the line number of the error (I guess it happens in the Typeahead class)?

@jay7793

This comment has been minimized.

jay7793 commented Oct 28, 2016

Hi @running-coder currently i'm switch to unminified version but problem still exists.

Image of Yaktocat

Thank you.

@running-coder

This comment has been minimized.

Owner

running-coder commented Oct 28, 2016

hmm the error does not come from Typeahead, looks like it's from your own code?

@jay7793

This comment has been minimized.

jay7793 commented Oct 28, 2016

Yeah, This my full code. Everything seems to be working fine but item object in the template function doesn't work .

       template: function (query, item) {
    var template =  '<span class="thumbnail"><img src="{{thumbnail}}"></span>' +
                  '<span class="detail">' +
                  '<span class="date">{{date}}</span>'+             
                  '<span class="title">{{title}}</span>' +
                  '<span class="meta">({{instructor}})</span>' +
                  '</span>'
      if (item.date) {
           template += '<span class="ribbon">Top Rated</span>';
      }
      return template;
},

running-coder added a commit that referenced this issue Oct 28, 2016

@running-coder

This comment has been minimized.

Owner

running-coder commented Oct 28, 2016

Hey, I was able to reproduce with your configurations. It was a special case with the combination of options you are using. Should be fixed now. Thanks for raising the issue!

@running-coder running-coder added the Bug label Oct 28, 2016

@running-coder running-coder added this to the 2.7.3 milestone Oct 28, 2016

running-coder added a commit that referenced this issue Nov 30, 2016

Version 2.7.3
- #251 Javascript error when using `correlativeTemplate` and a template function
- #256 Add clear function `resetInput` for Typeahead input
- #257 Allow to cancel the Ajax request before it's sent
- #261 Module export function call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment