|
120 | 120 | }
|
121 | 121 | };
|
122 | 122 |
|
123 |
| - var serializeObject = function ($elements) |
| 123 | + var serializeObject = function ($elements, skipEmpty, multipleSelects) |
124 | 124 | {
|
125 | 125 | // http://stackoverflow.com/a/1186309/8037
|
126 | 126 | var data = {};
|
127 | 127 |
|
128 | 128 | $.each($elements.serializeArray(), function ()
|
129 | 129 | {
|
130 |
| - if (data[this.name] !== undefined) |
| 130 | + if (this.value == '' && skipEmpty) |
| 131 | + this.value = null; |
| 132 | + else if (this.value == null && !skipEmpty) |
| 133 | + this.value = ''; |
| 134 | + |
| 135 | + var isMultipleSelect = $.inArray(this.name, multipleSelects) != -1; |
| 136 | + |
| 137 | + if (this.value == null && !isMultipleSelect) |
| 138 | + return; |
| 139 | + |
| 140 | + if (data[this.name] !== undefined || isMultipleSelect) |
131 | 141 | {
|
132 |
| - if (!data[this.name].push) |
| 142 | + if (data[this.name] == null) |
| 143 | + data[this.name] = []; |
| 144 | + else if (!data[this.name].push) |
133 | 145 | data[this.name] = [data[this.name]];
|
134 | 146 |
|
135 |
| - data[this.name].push(this.value || ''); |
| 147 | + data[this.name].push(this.value); |
136 | 148 | }
|
137 | 149 | else
|
138 | 150 | {
|
139 |
| - data[this.name] = this.value || ''; |
| 151 | + data[this.name] = this.value; |
140 | 152 | }
|
141 | 153 | });
|
142 | 154 |
|
|
230 | 242 | {
|
231 | 243 | resetContext
|
232 | 244 | .find("[data-griddly-filter-isnoneall=true] [multiple] option[value='']")
|
233 |
| - .prop("selected", false); |
| 245 | + .each(function () |
| 246 | + { |
| 247 | + if (newFilters[$(this).closest("[data-filter-field]").data("filter-field")] == null) |
| 248 | + $(this).prop("selected", false); |
| 249 | + }); |
234 | 250 | }
|
235 | 251 | };
|
236 | 252 |
|
|
1710 | 1726 | $(".griddly-filter-cancel, button.close", this).off("click").on("click", function ()
|
1711 | 1727 | {
|
1712 | 1728 | if (self.$element.triggerHandler("beforeclear.griddly") !== false)
|
1713 |
| - self.setFilterValues(values, null, true, true); |
| 1729 | + self.setFilterValues(values, false); |
1714 | 1730 | });
|
1715 | 1731 | })
|
1716 | 1732 | .on("shown.bs.modal", function ()
|
|
1737 | 1753 | if (currencySymbol)
|
1738 | 1754 | this.options.currencySymbol = currencySymbol;
|
1739 | 1755 |
|
| 1756 | + var multipleSelects = []; |
| 1757 | + |
| 1758 | + this.$element.find("[data-griddly-filter-ismultiple=true]").each( |
| 1759 | + function (el, i) |
| 1760 | + { |
| 1761 | + return multipleSelects.push($(this).data("filter-field")); |
| 1762 | + }); |
| 1763 | + |
| 1764 | + this.options.multipleSelects = multipleSelects; |
| 1765 | + |
1740 | 1766 | $("form", this.$element).attr("onsubmit", "return false;");
|
1741 | 1767 |
|
1742 | 1768 | $("form", this.$element).on("submit", $.proxy(function (event)
|
|
1801 | 1827 | {
|
1802 | 1828 | var allFilters = this.getAllFilterElements();
|
1803 | 1829 |
|
1804 |
| - return serializeObject(allFilters); |
| 1830 | + return serializeObject(allFilters, true, this.options.multipleSelects); |
1805 | 1831 | },
|
1806 | 1832 |
|
1807 | 1833 | setFilterValue: function (field, value)
|
|
0 commit comments