Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
How Do I Add Options To Auto Complete From Variable via json materialize css

So Basically what im trying to do is have my for each function for firebase database append a new line to a json variable, and it does it successfully but when i try to init the auto complete box with that data, it doesnt work, its just a normal typing box, i have logged my json variable, and it comes out correct, but it doesnt init properly Heres All My Code:

Index.html

        <div class="input-field col s12">
          <i class="material-icons prefix">person</i>
          <input type="text" id="autocomplete-input" class="autocomplete">
          <label for="autocomplete-input">Autocomplete Test</label>
        </div>

index.js

          var autocompletejson
          const database = firebase.database()
          database.ref('FLSocial/Accounts/')
            .once('value', function (snapshot) { // <-- consider Promise API instead
              const sortedChildren = [];
              snapshot.forEach(childSnapshot => { sortedChildren.unshift(childSnapshot) }); // reverses the order
      
              sortedChildren.forEach(childSnapshot => {
                const childKey = childSnapshot.key;
                const childData = childSnapshot.val();
                
                /* rest of the code */
                autocompletejson += `
                "${childKey}": null,`;
                
                
      
                
                
                
              })
              setTimeout(test_autofill, 3000)
              //3 Seconds Later it runs the function grabbing the global variable and trying to init the auto complete with the data
            });

function test_autofill() {
  console.log(autocompletejson)
  $('input.autocomplete').autocomplete({
    data: {autocompletejson},
  });
}

Example They Gave On The MaterializeCSS website:

  $(document).ready(function(){
    $('input.autocomplete').autocomplete({
      data: {
        "Apple": null,
        "Microsoft": null,
        "Google": 'https://placehold.it/250x250'
      },
    });
  });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!