Skip to content
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

Token not defined error #49

Closed
gokite7 opened this issue Jul 6, 2019 · 4 comments
Closed

Token not defined error #49

gokite7 opened this issue Jul 6, 2019 · 4 comments
Labels
question Further information is requested

Comments

@gokite7
Copy link

gokite7 commented Jul 6, 2019

.

@TarekRaafat
Copy link
Owner

Hello @apasric4,

First of all, I'll assume you're using a proper data source instead of the one in JSFiddle because this one is dummy and not working.

Secondly, I guess the results list could be hidden, so try adding the below to your css file and let me know how it went.

#autoComplete_results_list {
   display: block;
   bottom: -120px;
   right: 433px;
}

@TarekRaafat TarekRaafat added the question Further information is requested label Jul 11, 2019
@kanine
Copy link

kanine commented Jul 20, 2019

When trying your sample code using an API the 'query' is not being passed into the fetch...

const source = await fetch(https://site.test/api?q=${query});

Uncaught (in promise) ReferenceError: query is not defined

That's a working endpoint, but as soon as it no longer throws the following error once the query variable is removed. So how should the query element be passed in to the src: object.

Note: the backticks are getting stripped from my post.

@TarekRaafat
Copy link
Owner

Hello @kanine,

The ${query} in the sample code was referring to below defined variable that reads from input field the users typed value.

// User search query
const query = document.querySelector("#autoComplete").value;

So the entire data method block looks like this

  data: {
    src: async () => {
      // Loading placeholder text
      document.querySelector("#autoComplete").setAttribute("placeholder", "Loading...");
      // API key token
      const token = "this is the API token number";
      // User search query
      const query = document.querySelector("#autoComplete").value;
      // Fetch External Data Source
      const source = await fetch(`https://www.site.test/api/search?key=${token}&q=${query}`);
      const data = await source.json();
      // Post loading placeholder text
      document.querySelector("#autoComplete").setAttribute("placeholder", "Food & Drinks");
      // Return Fetched data
      return data.recipes;
    },

Please try it and let me know how it went.

Cheers! :)

@kanine
Copy link

kanine commented Jul 22, 2019

Thanks, that's what I had ended up doing anyway so all good. I just thought there may have been another object reference I should have been using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants