Skip to content

Commit

Permalink
Enter key now also saves search
Browse files Browse the repository at this point in the history
  • Loading branch information
joostverhoog committed Jun 12, 2017
1 parent 3fd4b6c commit 2190d52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Binary file added assets/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 24 additions & 19 deletions src/RememberSearch/widget/RememberSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
========================
@file : RememberSearch.js
@version : 0.1
@version : 1.1
@author : Joost Verhoog
@date : Tue, 25 Apr 2017 10:45:55 GMT
@date : Mon, 12 Jun 2017 13:00:00 GMT
@copyright : Mendix 2
@license : Apache 2
Expand All @@ -15,7 +15,6 @@
Remembers the user's last search.
*/

// Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
define([
"dojo/_base/declare",
"mxui/widget/_WidgetBase",
Expand Down Expand Up @@ -114,32 +113,38 @@ define([
});
preventSetCookie = false;
};


var saveSearch = function (elem) {
if (preventSetCookie)
return;
var searchBar = getSearchBar(elem);
var cookieName = getCookieName(searchBar);
var values = [];
searchBar.find('input, textarea').each(function () {
values.push($(this).val());
});
searchBar.find('select').each(function () {
values.push($(this).find('option:selected').text());
});
document.cookie = cookieName + '=' + encodeURIComponent(JSON.stringify(values));
};

$(function() {
// Search button sets a cookie
$('.mx-grid-search-button').click(function () {
if (preventSetCookie)
return;
var searchBar = getSearchBar($(this));
var cookieName = getCookieName(searchBar);
var values = [];
searchBar.find('input, textarea').each(function () {
values.push($(this).val());
});
searchBar.find('select').each(function () {
values.push($(this).find('option:selected').text());
});
document.cookie = cookieName + '=' + encodeURIComponent(JSON.stringify(values));
saveSearch($(this));
});
// Pressing enter sets the cookie, too
$('.mx-grid-search-inputs .form-control').keypress(function (event) {
if (event.which == 13)
saveSearch($(this));
});

// Reset button clears the cookie
$('.mx-grid-reset-button').click(function () {
var searchBar = getSearchBar($(this));
var cookieName = getCookieName(searchBar);
document.cookie = cookieName + '=null';
});

setTimeout(fillForm, 1);
});

setTimeout(fillForm, 1);
Expand Down
Binary file modified test/widgets/Remember search.mpk
Binary file not shown.

0 comments on commit 2190d52

Please sign in to comment.