|
| 1 | +# Task 1 - Autocomplete |
| 2 | + |
| 3 | +## Task overview |
| 4 | + |
| 5 | +Create a function that, by a given array of strings, creates an autocomplete dropdown list |
| 6 | + |
| 7 | +* The function takes two parameters: |
| 8 | + * A **selector** that can be any CSS3 selector: |
| 9 | + * By id -`#id` |
| 10 | + * By class - `.class` |
| 11 | + * By node type - `div` |
| 12 | + * Or nested selectors - `#this .is a .nested.selector` |
| 13 | + * A suggestions array |
| 14 | + * Array of strings |
| 15 | + * **optional**, may not be provided |
| 16 | + |
| 17 | +The following must be implemented: |
| 18 | + |
| 19 | +* Adding a suggestion for each element from the suggestions array |
| 20 | +* Entering a string for autocomplete |
| 21 | + * Any suggestion that does not contain the autocomplete string must be hidden |
| 22 | + * When the autocomplete string is empty, all suggestions must be hidden |
| 23 | +* Adding a new string for suggestion |
| 24 | + * Clicking the "Add" button, must add the string from the autocomplete to the suggestions |
| 25 | + * If the new suggestion is already contained in the suggestions, skip it |
| 26 | + * A suggestion can be contained only once |
| 27 | +* Selecting a suggestion |
| 28 | + * Selecting a suggestion from the suggestions must be filled in the autocomplete input |
| 29 | + |
| 30 | +## Task requirements |
| 31 | + |
| 32 | +1. Use the HTML from the `index.html` file |
| 33 | +2. Each suggestion must have the following HTML: |
| 34 | + |
| 35 | + ```html |
| 36 | + <li class="suggestion"> |
| 37 | + <a href="#" class="suggestion-link">Apple</a> |
| 38 | + </li> |
| 39 | + ``` |
| 40 | + |
| 41 | +## Solution template and submission: |
| 42 | + |
| 43 | +- Use the following submission template: |
| 44 | + |
| 45 | +```js |
| 46 | +function solve(){ |
| 47 | + return function(selector, suggestionsArray){ |
| 48 | + //your code here |
| 49 | + }; |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +- Submit it in http://bgcoder.com |
| 54 | + |
| 55 | +### Example usage 1: |
| 56 | + |
| 57 | +```html |
| 58 | +<div class="autocomplete"> |
| 59 | + <input class="tb-pattern" type="text" /> |
| 60 | + <a href="#" class="btn-add">Add</a> |
| 61 | + <ul class="suggestions-list"> |
| 62 | + </ul> |
| 63 | +</div> |
| 64 | +<script> |
| 65 | +solve()("#root", ["Apples", "Oranges"]); |
| 66 | +</script> |
| 67 | +``` |
| 68 | + |
| 69 | +### Example usage 2: |
| 70 | + |
| 71 | +```html |
| 72 | +<div class="autocomplete"> |
| 73 | + <input class="tb-pattern" type="text" /> |
| 74 | + <a href="#" class="btn-add">Add</a> |
| 75 | + <ul class="suggestions-list"> |
| 76 | + </ul> |
| 77 | +</div> |
| 78 | +<script> |
| 79 | +solve()("#root"); |
| 80 | +</script> |
| 81 | +``` |
| 82 | + |
| 83 | +## Examples: |
| 84 | + |
| 85 | +- Autocomplete string is empty |
| 86 | + - No suggestions are shown |
| 87 | + |
| 88 | +<img src="sample-images/initial.png" /> |
| 89 | + |
| 90 | +- Autocomplete string is "a" |
| 91 | + - Some suggestions are shown |
| 92 | + |
| 93 | +<img src="sample-images/string-in-autocomplete-1.png" /> |
| 94 | + |
| 95 | +- Autocomplete string is "ap" |
| 96 | + - Some suggestions are shown |
| 97 | + |
| 98 | +<img src="sample-images/string-in-autocomplete-2.png" /> |
| 99 | + |
| 100 | +- The autocomplete string becomes "Apples" after the "Apples" suggestion is clicked |
| 101 | + |
| 102 | +<img src="sample-images/text-in-autocomplete-after-click-on-suggestion.png" /> |
| 103 | + |
| 104 | +- No suggestion matches the autocomplete srtring "Pineapple" |
| 105 | + - No suggestions are shown |
| 106 | + |
| 107 | +<img src="sample-images/no-suggestion-matches-autocomplete-string.png" /> |
| 108 | + |
| 109 | +- After clicking the "Add" button the new suggestion "Pineapple" is added |
| 110 | + |
| 111 | +<img src="sample-images/new-suggestion-added.png" /> |
| 112 | + |
| 113 | +## Additional Requirements |
| 114 | + |
| 115 | +- You are **NOT** allowed to alter the HTML or the CSS in any way |
| 116 | + - Keep in mind, the tests use the original HTML and CSS |
| 117 | +- Write all your code only in the `task-1.js` file |
| 118 | +- Mandatory hide elements with `display: none` |
| 119 | +- Use `input` event on the autocomplete `<input />` |
0 commit comments