#AutocompleteSearch
Explore tagged Tumblr posts
codesolutionsstuff · 3 years ago
Text
Laravel 9 Autocomplete Search using Typeahead JS Tutorial
Tumblr media
I'll show you today how to use typeahead js to make autocomplete search in Laravel 9. We'll demonstrate a typeahead js-based Laravel 9 autocomplete search. We will demonstrate how to create a search autocomplete box in Laravel 9 using jQuery Typehead and ajax. I'll utilize the bootstrap library, the jQuery typehead js plugin, and ajax to add search autocomplete to my Laravel 9 application. Here, I'll offer you a detailed example of how to use typeahead js with Laravel 9's ajax autocomplete search as shown below.
Step 1: Install Laravel 9 Application
Since we are starting from scratch, the following command must be used to obtain a new Laravel application. Open a terminal or a command prompt, then enter the following command: composer create-project --prefer-dist laravel/laravel Laravel9TypeheadTutorial
Step 2: Database Configuration
Configure your downloaded/installed Laravel 9 app with the database in this stage. The .env file must be located, and the database setup information is as follows: DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=db name DB_USERNAME=db user name DB_PASSWORD=db password
Step 3: Add Dummy Record
I'll create fictitious records for database table users in this stage. Open the DatabaseSeeder.php file by going to the database/seeders/ directory. Add the next two lines of code after that. use AppModelsUser; User::factory(100)->create(); Then, launch command prompt, and use the following command to go to your project: cd / Laravel9TypeheadTutorial Open your terminal once more, and then type the following command on cmd to create tables in the database of your choice: php artisan migrate Run the database seeder command after that to create dummy data for the database: php artisan db:seed --force
Step 4: Create Routes
Open the web.php file, which is found in the routes directory, in this step. Add the following routes to the web.php file after that: use AppHttpControllersAutocompleteSearchController; Route::get('/autocomplete-search', )->name('autocomplete.search.index'); Route::get('/autocomplete-search-query', )->name('autocomplete.search.query');
Step 5: Creating Auto Complete Search Controller
The following command will be used to create the search AutocompleteSearch controller in this stage. php artisan make:controller AutocompleteSearchController The AutocompleteSearchController.php file will be created by the aforementioned command and placed in the Laravel8TypeheadTutorial/app/Http/Controllers/ directory. Subsequently, include the following controller methods in AutocompleteSearchController.blade.php: Read the full article
0 notes
jeeteshsurana · 6 years ago
Link
AutoCompleteTextView
XML
  <AutoCompleteTextView
                    android:id="@+id/edt_product_search"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/search"
                    android:layout_weight="1"
                    android:inputType="text"
                    android:imeOptions="actionSearch"
                    android:background="@android:color/transparent"
                    android:textColorHint="#B3B3B3"
                    android:textStyle="italic"/>
Kt
var searchWord = ""
var mAutoCompleteSearchWords = ArrayList<String>()
init(){
edt_product_search.setOnClickListener {
            mAutoCompleteSearchWords = getAutoCompleteSearchList()
            if (!mAutoCompleteSearchWords.isNullOrEmpty() && mAutoCompleteSearchWords.size > 0) {
                edt_product_search.threshold = 1
                val adapter = ArrayAdapter<String>(context!!, android.R.layout.select_dialog_item, mAutoCompleteSearchWords)
                edt_product_search.setAdapter(adapter)
            }
        }
}
private fun searchProductValidation() {
    val searchProduct = edt_product_search.text.toString()
    searchWord = searchProduct
    if (searchProduct.isEmpty()) {
        Toast.makeText(activity, resources.getString(R.string.msg_search), Toast.LENGTH_SHORT)
.show()
    } else {
        //Your Function
    }
    edt_product_search.setText("")
}
//getting search
private fun openFragment() {
    mSearchProductListFragment.lastname = searchWord    
    if (!mAutoCompleteSearchWords.contains(searchWord))
    mAutoCompleteSearchWords.add(searchWord)
         setAutoCompleteSearchList()
     }
//get the save search words from arrayList by sharedPreference
private fun getAutoCompleteSearchList(): ArrayList<String> {
    val type = object : TypeToken<ArrayList<String>>() {}.type    var autoCompleteSearch = ArrayList<String>()
    val json = mBaseActivity!!.mPreferenceManager!!.getValue(Constants.autoCompleteSearch, "")
    if (!json.isNullOrEmpty()) autoCompleteSearch = Gson().fromJson(json, type)
    return autoCompleteSearch
}
 //save the search in arrayList and sharedPreference
private fun setAutoCompleteSearchList() {
    mBaseActivity!!.mPreferenceManager!!.setValue(Constants.autoCompleteSearch, Gson().toJson(mAutoCompleteSearchWords))
}
0 notes
jeeteshsurana · 6 years ago
Text
AutoCompleteTextView [search edittext]
http://bit.ly/2GhiuqO
AutoCompleteTextView
XML
  <AutoCompleteTextView
                    android:id="@+id/edt_product_search"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/search"
                    android:layout_weight="1"
                    android:inputType="text"
                    android:imeOptions="actionSearch"
                    android:background="@android:color/transparent"
                    android:textColorHint="#B3B3B3"
                    android:textStyle="italic"/>
Kt
var searchWord = ""
var mAutoCompleteSearchWords = ArrayList<String>()
init(){
edt_product_search.setOnClickListener {
            mAutoCompleteSearchWords = getAutoCompleteSearchList()
            if (!mAutoCompleteSearchWords.isNullOrEmpty() && mAutoCompleteSearchWords.size > 0) {
                edt_product_search.threshold = 1
                val adapter = ArrayAdapter<String>(context!!, android.R.layout.select_dialog_item, mAutoCompleteSearchWords)
                edt_product_search.setAdapter(adapter)
            }
        }
}
private fun searchProductValidation() {
    val searchProduct = edt_product_search.text.toString()
    searchWord = searchProduct
    if (searchProduct.isEmpty()) {
        Toast.makeText(activity, resources.getString(R.string.msg_search), Toast.LENGTH_SHORT)
.show()
    } else {
        //Your Function
    }
    edt_product_search.setText("")
}
//getting search
private fun openFragment() {
    mSearchProductListFragment.lastname = searchWord    
    if (!mAutoCompleteSearchWords.contains(searchWord))
    mAutoCompleteSearchWords.add(searchWord)
         setAutoCompleteSearchList()
     }
//get the save search words from arrayList by sharedPreference
private fun getAutoCompleteSearchList(): ArrayList<String> {
    val type = object : TypeToken<ArrayList<String>>() {}.type    var autoCompleteSearch = ArrayList<String>()
    val json = mBaseActivity!!.mPreferenceManager!!.getValue(Constants.autoCompleteSearch, "")
    if (!json.isNullOrEmpty()) autoCompleteSearch = Gson().fromJson(json, type)
    return autoCompleteSearch
}
 //save the search in arrayList and sharedPreference
private fun setAutoCompleteSearchList() {
    mBaseActivity!!.mPreferenceManager!!.setValue(Constants.autoCompleteSearch, Gson().toJson(mAutoCompleteSearchWords))
}
via Blogger http://bit.ly/2GjuXLP
0 notes