Skip to content

Commit 0ca94f6

Browse files
committed
only refresh page if from and to values are set
1 parent 79d1e39 commit 0ca94f6

File tree

5 files changed

+6826
-26
lines changed

5 files changed

+6826
-26
lines changed

dist/js/filter.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
1111
},
1212
"devDependencies": {
13-
"cross-env": "^5.0.0",
14-
"laravel-mix": "^5.0.0",
15-
"vue-template-compiler": "^2.6.10"
13+
"cross-env": "^6.0.3",
14+
"laravel-mix": "^5.0.1",
15+
"vue-template-compiler": "^2.6.11"
1616
},
1717
"dependencies": {
18-
"vue": "^2.5.0"
18+
"vue": "^2.6.11"
1919
}
2020
}

resources/js/components/RangeInputFilter.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<template>
22

3-
<div>
3+
<div class="range-input-filter">
44

55
<h3 class="text-sm uppercase tracking-wide text-80 bg-30 p-3">
66
{{ filter.name }}
77
</h3>
88

9-
<div class="flex p-2 flex-wrap items-center">
9+
<div class="flex p-2 flex-no-wrap items-center">
1010

11-
<input class="flex items-center form-control form-input text-sm min-w-0 border-60"
12-
:class="{ 'flex-1': filter.options.fullWidth }"
11+
<input class="flex items-center form-control form-input text-sm border-60"
12+
:class="{ 'w-full': filter.options.fullWidth }"
1313
name="from"
1414
:type="filter.options.inputType"
1515
:placeholder="filter.options.fromPlaceholder"
16-
:value="value.from"
16+
v-model="value.from"
1717
@change="handleChange"/>
1818

19-
<div class="text-sm mx-2">{{ filter.options.dividerLabel }}</div>
19+
<div class="text-sm mx-2 text-center">{{ filter.options.dividerLabel }}</div>
2020

21-
<input class="flex items-center form-control form-input text-sm min-w-0 border-60"
22-
:class="{ 'flex-1': filter.options.fullWidth }"
21+
<input class="flex items-center form-control form-input text-sm border-60"
22+
:class="{ 'w-full': filter.options.fullWidth }"
2323
name="to"
2424
:type="filter.options.inputType"
2525
:placeholder="filter.options.toPlaceholder"
26-
:value="value.to"
26+
v-model="value.to"
2727
@change="handleChange"/>
2828

2929
</div>
@@ -49,6 +49,16 @@
4949
methods: {
5050
handleChange(event) {
5151
52+
/**
53+
* Dont refresh the page if user is still typing the values
54+
*/
55+
if (Number.isNaN(parseInt(this.value.from)) !==
56+
Number.isNaN(parseInt(this.value.to))) {
57+
58+
return
59+
60+
}
61+
5262
this.$store.commit(`${ this.resourceName }/updateFilterState`, {
5363
filterClass: this.filterKey,
5464
value: {
@@ -66,10 +76,7 @@
6676
return this.$store.getters[ `${ this.resourceName }/getFilter` ](this.filterKey)
6777
},
6878
value() {
69-
return this.filter.currentValue || {
70-
from: null,
71-
to: null
72-
}
79+
return { ...this.filter.currentValue } || { from: '', to: '' }
7380
}
7481
}
7582
}

src/RangeInputFilter.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ class RangeInputFilter extends Filter
1414
*/
1515
public $component = 'range-input-filter';
1616

17+
/**
18+
* @var array
19+
*/
20+
public $defaults = [
21+
'fromPlaceholder' => null,
22+
'toPlaceholder' => null,
23+
'inputType' => 'number',
24+
'dividerLabel' => 'to',
25+
'fullWidth' => true
26+
];
27+
1728
/**
1829
* @param Request $request
1930
* @param Builder $query
@@ -35,13 +46,7 @@ public function apply(Request $request, $query, $value)
3546
*/
3647
public function options(Request $request): array
3748
{
38-
return [
39-
'fromPlaceholder' => null,
40-
'toPlaceholder' => null,
41-
'inputType' => 'number',
42-
'dividerLabel' => 'to',
43-
'fullWidth' => true
44-
];
49+
return [];
4550
}
4651

4752
/**
@@ -51,7 +56,9 @@ public function options(Request $request): array
5156
*/
5257
public function jsonSerialize(): array
5358
{
54-
return array_merge(parent::jsonSerialize(), [ 'options' => $this->options(resolve(Request::class)) ]);
59+
return array_merge(
60+
parent::jsonSerialize(), [ 'options' => array_merge($this->defaults, $this->options(resolve(Request::class))) ]
61+
);
5562
}
5663

5764
}

0 commit comments

Comments
 (0)