Pure JS Auto Complete plugin with extra features.

Overview

Cndk.AutoComplete.js

alt text

alt text

Cndk.AutoComplete.js is a pure JavaScript plugin. It performs auto-complete operations within an INPUT.

Installation

Include the CSS file.

<link href="/cndk.autocomplete.css" rel="stylesheet" type="text/css">

Include the JS file.

<script src="/cndk.autocomplete.js" type="text/javascript"></script>

How To Use

Javascript Init

<script>
        var autoComplete = new CndkAutoComplete(
        {
           input: '#inputCountry',
           ajaxFile: '/demos/json/phone_codes.json'
        });
</script>

input : Selector of a input. You can use class name '.' or id '#'.

ajaxFile : JSON file.

HTML Code

<input type="text" id="inputCountry" name="country" class="form-control" placeholder="Search" autofocus="">

JSON Example

text and id variables are required. It would be helpful if the id value was unique. You can send additional keys in the JSON file. Use these switches in the design regulations.

[
    {
        // Default keys
        "text": "Germany",
        "id": "1",

        // Extra keys
        "flag": "https://www.countryflags.io/de/flat/32.png",
        "code": "+144"
    },
    ...
]

Default Options

// Default options
        var defaults = {
            input: '', /* Input selector with classname (.) or  ID (#) */
            ajaxFile: '', /* Static or dynamic AjaxFile URL */
            type: 'static', /* static | dynamic */
            minCharsToSearch: 1, /* Min chars to search in items */
            itemsShow: 5, /* Max items to show on list */
            autoFocusWhenSelect: null, /* Focus another input element when any item has been selected */
            disableInputOnSelect: false, /* Disable input if any item has been selected */
            showAllOnInputClick: true, /* Shows all items when value length = 0 and options is = true */
            submitFormOnEnter: false, /* Submit form when press Enter key on the keyboard */
            submitFormOnItemSelect: false, /* Submit form when any item has been selected */
            submitValueType: '${id}', /* $text | $id */
            itemLayout: '${text}', /* Can be used of any json value like in .JSON response => $id | $text | $url */
            itemInputLayout: '${text}', /* Can be used of any json value like in .JSON response => $id | $text | $url */
            rootDivId: "cndkAutoComplete",
            itemClass: 'cndk-item',
            itemClassActive: 'cndk-item-active',
            theme: 'light' /* light | dark */
        }

Custom Item Layout (List) and (Input)

itemLayout refers to the view in the list. itemInputLayout represents the input value. Here you can use any extra key from json file.

<script>
        var autoComplete = new CndkAutoComplete(
            {
                ...
                itemLayout: '<img style="width:15px;" src="${flag}"/> ${text} (<em>${code}</em>)',
                itemInputLayout: '${code}'
            });
    </script>

Sample JSON file response of the above example.

[
    {
        "text": "Germany",
        "id": "1",
        "flag": "https://www.countryflags.io/tr/flat/32.png",
        "code": "+144"
    },
]

Options

input NULL (Required)

Input selector with classname (.) or ID (#). You can use the default JQuery selectors.

ajaxFile NULL (Required)

Static or dynamic AjaxFile URL. The response should be as in the example above.

type static (Optional)

It can take "static" or "dynamic" values. Statically sent data is preloaded. Dynamically sent data is received during execution.

minCharsToSearch 1 (Optional)

A call is made when the total length in the input exceeds this value.

itemsShow 5 (Optional)

Max items to show on list.

autoFocusWhenSelect NULL (Optional)

Focus another input element when any item has been selected. Here you can send a different element as in the input value. Example: autoFocusWhenSelect: '#anotherInput'

disableInputOnSelect false (Optional)

Disable input if any item has been selected.

showAllOnInputClick true (Optional)

Shows all items when click on input if value not length = 0.

submitFormOnEnter false (Optional)

Submit form when press Enter key on the keyboard.

submitFormOnItemSelect false (Optional)

Submit form when any item has been selected.

submitValueType ${id} (Optional)

You can specify which data type to send when the form is submitted.

itemLayout ${text} (Optional)

You can specify how the elements in the list appear. You can use HTML code. You can also use any key returned from JSON data. Example: itemLayout: '<img style="width:15px;" src="${flag}"/> ${text} (<em>${code}</em>)','

itemInputLayout ${text} (Optional)

You can specify how the input value will appear when an element is selected. HTML code cannot be used. You can also use any key returned from JSON data. Example: itemInputLayout: '${text}' or itemInputLayout: '${id}'

theme light (Optional)

You can use 'light' or 'dark' theme mode.

License

MIT

You might also like...

Extra modifications and enhancements for Discord Bot Maker. Mods you won't find on the DBM Network!

Extra modifications and enhancements for Discord Bot Maker. Mods you won't find on the DBM Network!

DBM Extended is a open source project meant to enhance and extend Discord Bot Maker. Downloads This repository is not meant to be downloaded or cloned

Oct 10, 2022

A JSX transformer with extra hints around interpolations and outer templates.

@ungap/babel-plugin-transform-hinted-jsx This plugin is a follow up of this post and it can be used together with @babel/plugin-transform-react-jsx. A

Nov 12, 2022

Obsidian plugin that adds autocomplete and auto-formatting to frontmatter tags.

Obsidian plugin that adds autocomplete and auto-formatting to frontmatter tags.

Obsidian Front Matter Tag Wizard Tired of having to type # to get tag autocompletion in your Obsidian note front matter? I feel your pain. This plugin

Nov 5, 2022

A plugin for Strapi that provides the ability to auto slugify a field for any content type

strapi-plugin-slugify A plugin for Strapi that provides the ability to auto slugify a field for any content type. It also provides a findOne by slug e

Nov 28, 2022

infiniteScrollWithTemplate - JQuery plugin for ajax-enabled infinite page scroll / auto paging with template

jQuery Infinite With Template Plugin JQuery plugin for ajax-enabled infinite page scroll with template. If you like jQuery until now, this little libr

Mar 19, 2021

Toaster is a Pure Javascript plugin for displaying toast notifications. It comes with different options e.g custom text or HTML message, duration, custom class, toggle close button, position, custom close icon and backgorund color.

Pure Javascript Toaster Requires Nothing Demo Toaster is a Pure Javascript plugin for displaying toast notifications. It comes with different options

Jun 21, 2022

A Tailwind plugin that allows to create multiple groups utilities such as group-card or group-1 and works with Tailwind 3 features and all variations.

Tailwind Labeled Groups A plugin that allows to create multiple groups utilities such as group-card or group-1 and works with Tailwind 3 features and

Nov 21, 2022

ESLint plugin about ECMAScript syntactic features.

eslint-plugin-es-x ESLint plugin which disallows each ECMAScript syntax. Forked from eslint-plugin-es. As the original repository seems no longer main

Dec 6, 2022

An obsidian plugin that give additional features to code blocks.

An obsidian plugin that give additional features to code blocks.

Obsidian Advanced Codeblock Add additioinal features to code blocks. Demo Feature Add line numbers to code block Add line highlight to code block Usag

Jan 3, 2023
Owner
ILKERC
ILKERC
Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

parallax-vanilla.js Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra perfo

Erik Engervall 91 Dec 16, 2022
This is a JQuery plugin for input tags with auto complete suggestion.

Jquery Suggestags This is a JQuery plugin for input tags with auto complete suggestion. $('input').amsifySuggestags(); npm installation npm i suggesta

Amsify42 60 Nov 16, 2022
Multi-chain defi crypto sniper written in typescript/javascript. Fastest method of sniping with auto-sell and rug prevention features.

CryptoSniper Community Edition Multi-chain defi crypto sniper written in typescript/javascript. Fastest method of sniping with auto-sell and rug preve

null 18 Nov 3, 2022
Instagram.css - Complete set of Instagram filters in pure CSS

Instagram.css Instagram.css - Pure CSS Instagram filters. You can add all these Instagram-like filters to your photos with using CSS only. Thanks to t

Yan Zhu 4k Dec 30, 2022
DevArms - a collection of developer utils that gives you extra arms to reach more in your tasks

DevArms is a collection of developer utils that gives you extra arms to reach more in your tasks. It runs completely offline, and cross-platform across Windows, Mac and Linux. Written in Rust, React. Powered by Tauri.

Qiushi Pan 82 Dec 18, 2022
Lavalink client with lots of extra functionality, easy to use and well optimized.

?? nSysLava Lavalink client with lots of extra functionality, easy to use and well optimized! พัฒนาโดยคนไทย ?? Many utility functions - มีฟังก์ชันอรรถ

nicenathapong 3 Apr 12, 2022
Extended magic-string with extra utilities

DEPRECATED. It has been ported back to magic-string >= 0.26.0 magic-string-extra Extended Rich-Harris/magic-string with extra utilities. Install npm i

Anthony Fu 130 Sep 8, 2022
Completely free TS/JS one-file source code snippets with tests, which can be copied to avoid extra dependencies (contributions welcome).

TinySource Completely free TS/JS one-file source code snippets with tests, which can be copied to avoid extra dependencies (contributions welcome). Sn

null 81 Jan 3, 2023