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

158
Views
Compruebe si el valor de textboxt existe en Typeahead

Tengo esta línea de códigos que obtendrán toda la ubicación en mi base de datos cuando el usuario escriba en mi cuadro de texto. El problema es que quiero validar cuando el usuario cambia el texto en mi cuadro de texto y no existe en mi escritura anticipada.

 var path = "{{ route('search.location') }}"; $('input.typeahead').typeahead({ source: function (query, process) { return $.get(path, { query: query }, function (data) { return process(data); }); } }).blur(function () { if(source.indexOf($(this).val()) === -1) alert('Not exists'); });

He investigado un poco usando la función .blur pero no puedo hacer que funcione.

 ReferenceError: source is not defined
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Este es un ejemplo con datos locales. La variable booleana algo se establece en verdadero, si la consulta al menos coincide con un elemento.

 $( document ).ready(function() { var data = [ {value: "Alabama"}, {value: "Delaware"}, {value: "Maine"} ]; var somethingFound = false; $("#the-basics .typeahead").typeahead( { minLength: 1, highlight: true }, { source: function(query, syncResults, asyncResults) { // use query to filter data var filteredData = data.filter(function(e){ return e.value.toLowerCase().startsWith(query.toLowerCase()); }); console.log(filteredData.length); somethingFound = filteredData.length > 0; // return filtered data syncResults(filteredData); } }).blur(function(){ if (!somethingFound) { alert('nothing found'); } }); });

ver también en Plunker

about 4 years ago · Santiago Trujillo Report
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!