Skip to content

Commit

Permalink
Improve reset logic ...
Browse files Browse the repository at this point in the history
Only reset when the value doesn't exist in the new options.

Ref #398
  • Loading branch information
jasonvarga committed Dec 4, 2019
1 parent 938d514 commit 170676b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 13 additions & 1 deletion resources/js/components/fieldtypes/SelectFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:taggable="config.taggable"
:push-tags="config.push_tags"
:multiple="config.multiple"
:reset-on-options-change="typeof config.reset_on_options_change === 'boolean' ? config.reset_on_options_change : true"
:reset-on-options-change="resetOnOptionsChange"
:close-on-select="!config.taggable"
:value="value" />
</template>
Expand All @@ -27,6 +27,18 @@ export default {
computed: {
options() {
return this.normalizeInputOptions(this.config.options);
},
resetOnOptionsChange() {
// Reset logic should only happen when the config value is true.
// Nothing should be reset when it's false or undefined.
if (this.config.reset_on_options_change !== true) return false;
// Reset the value if the value doesn't exist in the new set of options.
return (options, old, val) => {
let opts = options.map(o => o.value);
return !val.some(v => opts.includes(v.value));
};
}
},
Expand Down
3 changes: 0 additions & 3 deletions src/Query/Scopes/Filters/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public function fieldItems()
'options' => $options,
'clearable' => true,
'multiple' => true,

// This can be removed if/when https://github.com/sagalbot/vue-select/pull/1014 is merged
'reset_on_options_change' => false,
],
];
}
Expand Down

0 comments on commit 170676b

Please sign in to comment.