-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #495 - Adds input clear button
- Adds search input manager for handling input clear button—little (x). - Disables autocomplete because field highlight color can’t be overridden. - Removes unused data-list attributes. - Adds tests for clearing the input fields.
- Loading branch information
1 parent
ffbcaa4
commit 042b015
Showing
13 changed files
with
808 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Handles functionality of search inputs, such as how the inputs are cleared. | ||
define( | ||
function () { | ||
'use strict'; | ||
|
||
// A list of elements with the clearable class. | ||
var _inputs; | ||
|
||
function init() { | ||
// Find all elements with the clearable class. | ||
_inputs = document.querySelectorAll('.clearable'); | ||
|
||
for (var i = 0, len = _inputs.length; i < len; i++) { | ||
_initCloseButton(_inputs[i]) | ||
} | ||
|
||
// Find the global reset button so all search inputs can be cleared. | ||
var buttonReset = document.getElementById('button-reset'); | ||
buttonReset.addEventListener('click', _resetClicked); | ||
} | ||
|
||
function _resetClicked(evt) { | ||
var closeButton; | ||
for (var i = 0, len = _inputs.length; i < len; i++) { | ||
closeButton = _inputs[i].querySelector('.button-close'); | ||
closeButton.classList.add('hide'); | ||
} | ||
} | ||
|
||
// @param inputContainer [Object] The container element enclosing an | ||
// input field and close button. | ||
function _initCloseButton(inputContainer) { | ||
|
||
// Retrieve first and only input element. | ||
var input = inputContainer.getElementsByTagName('input')[0]; | ||
|
||
// Create a clear button dynamically. | ||
var buttonClear = document.createElement('button'); | ||
buttonClear.className = 'button-close'; | ||
if (input.value === '') | ||
buttonClear.className += ' hide'; | ||
inputContainer.appendChild(buttonClear); | ||
|
||
buttonClear.addEventListener('click', function (evt) { | ||
evt.preventDefault(); | ||
input.value = ''; | ||
buttonClear.classList.add('hide'); | ||
input.focus(); | ||
}) | ||
|
||
input.addEventListener('keyup', function (evt) { | ||
_checkClearButtonVisibility(input, buttonClear); | ||
}) | ||
|
||
input.addEventListener('change', function (evt) { | ||
_checkClearButtonVisibility(input, buttonClear); | ||
}) | ||
} | ||
|
||
// @param input [Object] The input field where a search is entered. | ||
// @param buttonClear [Object] The clear button for clearing the form. | ||
function _checkClearButtonVisibility(input, buttonClear) { | ||
if (input.value === '') | ||
buttonClear.classList.add('hide'); | ||
else | ||
buttonClear.classList.remove('hide'); | ||
} | ||
|
||
return { | ||
init:init | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
// manages search initialization | ||
require(['search/search-filter-manager'], | ||
function (filter) { | ||
// Manages search initialization. | ||
require([ | ||
'search/search-filter-manager', | ||
'search/input-manager' | ||
], | ||
function (filter, input) { | ||
'use strict'; | ||
|
||
filter.init(); | ||
input.init(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
= field_set_tag nil, id: 'org-name-options', class: 'input-search-filter' do | ||
= label_tag 'org_name', t('labels.agency_search') | ||
= content_tag :div, '', class: 'filter-input-group' do | ||
= button_tag(type: 'submit', name: nil) do | ||
= content_tag :div, '', class: 'filter-input-group clearable' do | ||
= button_tag(type: 'submit', name: nil, class: 'button-icon') do | ||
= content_tag :i, '', class: 'fa fa-institution' | ||
= search_field_tag :org_name, params[:org_name], placeholder: t('placeholders.agency_search'), list: 'search-agency' | ||
= search_field_tag :org_name, params[:org_name], autocomplete: 'off', placeholder: t('placeholders.agency_search') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
= field_set_tag nil, id: 'location-options', class: 'input-search-filter input-search-filter-option' do | ||
= label_tag 'location', t('labels.address_search') | ||
= content_tag :div, '', class: 'filter-input-group' do | ||
= button_tag(type: 'submit', name: nil) do | ||
= content_tag :div, '', class: 'filter-input-group clearable' do | ||
= button_tag(type: 'submit', name: nil, class: 'button-icon') do | ||
= content_tag :i, '', class: 'fa fa-map-marker' | ||
= search_field_tag :location, params[:location], placeholder: t('placeholders.address_search'), list: 'search-location' | ||
= search_field_tag :location, params[:location], autocomplete: 'off', placeholder: t('placeholders.address_search') | ||
= render 'component/search/geolocate', context_class: 'input-search-filter-option' |
Oops, something went wrong.