Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support option with disabled property #309

Closed

Conversation

markselby9
Copy link

@markselby9 markselby9 commented Sep 6, 2017

1, Add support for options with disabled property
2, Add corresponding test case and demo

issue reference: #104

1, Add support for options with disabled property
2, Add corresponding test case and demo
@markselby9
Copy link
Author

#116

@closuresandcoffee
Copy link

This is great. +1 for merging this request.

@sagalbot
Copy link
Owner

sagalbot commented Oct 1, 2017

@markselby9 thanks for the contribution!

I think this is an important feature, but the implementation needs to be a bit more abstract. The component needs to remain as agnostic of the data source as possible. Perhaps there are options that need to be disabled, but the disabled key doesn't exist on their data, and they're unable to modify it. Similar to the label prop, you need to be able to define your own key for disabled.

1. Add a custom disabled key
2. Modify the demo for this feature
# Conflicts:
#	src/components/Select.vue
@markselby9
Copy link
Author

@sagalbot
I've added an 'disabledkey' for the user to define their own key for disabled, along with test cases and demo.
Thanks for your tips, it's simple and clear 👍

@bcreeves
Copy link

bcreeves commented Mar 1, 2018

Any timeline for when this gets merged and released?

@Anatakun
Copy link

Same question : When will this be available ?
I need this for a project, so i'll fork if needed, but it seems i'm not thinking it's really useful and nearly merged into the master.
Thx

@r3cha
Copy link

r3cha commented Apr 11, 2018

@sagalbot Do you need any help with merge this in master branch?

@r3cha
Copy link

r3cha commented Jun 17, 2018

To anybody that need to use this feature I create fork and merge this pull request.
Works good, thanks @markselby9
@sagalbot may be create some branch with fast forward accepted new features that we can test it on live projects and make feedback?

@noahduncan
Copy link

I'd also love to see this feature merged. Could use it right now! :)

@Phoxloxley
Copy link

Has anyone looked at this merge conflict recently? This is a useful feature, I hate to see issues in PRgatory. Also it is Hacktoberfest right now, this could help resolve this easily.

@r3cha
Copy link

r3cha commented Oct 18, 2018

Here is I merge it
r3cha#1 in my fork, but probably current master at main repo is ahed of mine, because I did it more than 6 month ago

@gr8bit gr8bit mentioned this pull request Jan 7, 2019
@reppair
Copy link

reppair commented Mar 26, 2019

@sagalbot any chance this gets merged soon? It is an useful feature.

@r3cha
Copy link

r3cha commented Mar 26, 2019

@sagalbot any chance this gets merged soon? It is an useful feature.

It was in 2018 :(
Probably he didn't have time for this

@sagalbot sagalbot added this to In progress in Active PRs via automation Mar 26, 2019
@sagalbot sagalbot self-assigned this Mar 26, 2019
@sagalbot
Copy link
Owner

sagalbot commented Mar 26, 2019

Sorry for the long wait on this one, it's definitely one that should get in. The most recent changes are definitely a step in the right direction.

For v3, I've removed the index string prop #800 that allowed you to return an object key to v-model, replacing it with a reduce Function prop that allows you to transform an object (or primitive) however you need before passing it to the input event.

Thinking more about this, I think the best option is perhaps a single Function prop, maybe named selectable. By default, it'd be essentially a no-op function that returns true.

      selectable: {
        type: Function,
        default: option => true,
      },

This function would determine wether the select() method is bound to an option on click, and add a vs__option--disabled class to the item in the list.

Internally, this function would always be evaluated as a boolean. This provides a pretty basic, but powerful API. If your data set happens to have a disabled key, you'd implement as such:

<v-select :selectable="option => ! option.disabled" />

It's only a few more words to type than specifying an object key, but it'd also support more complex situations. For example, a list of people that you can select. In this case, you should only be able to select people that are above the age of 20.

<v-select :selectable="person => person.age >= 20" />

Or perhaps your disable key is deeply nested in an object:

<v-select :selectable="option => ! option.meta.isDisabled" />

It would also work with primitives:

<v-select :options="[1,2,3,4,5]" :selectable="num => num < 3" />

This approach means that vue-select makes zero assumptions about the source data, and works with both objects and primitive options. It is a slightly more complex API than simply providing a string, but is significantly more flexible.

@sagalbot
Copy link
Owner

Related: #803

@sagalbot sagalbot removed this from In progress in Active PRs Mar 29, 2019
@sagalbot sagalbot added this to In progress in v3 via automation Mar 29, 2019
@sagalbot sagalbot moved this from In progress to To do in v3 Apr 8, 2019
@doits
Copy link
Contributor

doits commented Jul 11, 2019

:selectable feels good to me! Is there a timeline when this will be implemented?

@alxgb
Copy link

alxgb commented Jul 12, 2019

Agree that the :selectable API sounds pretty good, and considering this is a base feature of a browser select, it should definitely be in the library!

@huglester
Copy link

any progress on this?

@wilian746
Copy link

wilian746 commented Jul 31, 2019

any progress on this? @sagalbot pliss?

@doits
Copy link
Contributor

doits commented Jul 31, 2019

@wilian746 see #921 for an initial implementation - feel free to test and report back your findings (must run yarn build though to have it compiled in dist folder - see #921 for instructions how to test it)

@sagalbot
Copy link
Owner

Closing in favor of the selectable prop in #921. Will be released in 3.3!

@sagalbot sagalbot closed this Oct 26, 2019
v3 automation moved this from To do to Done Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
v3
  
Done
Development

Successfully merging this pull request may close these issues.

None yet