ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

Proposal: adding static choices

Open dimirc opened this issue 9 years ago • 65 comments

There are cases where we might need to show some static info at the dropdown. We could add a new directive ui-select-static-choice and I was thinking of something like this:

  <ui-select ng-model="person.selected">
    <ui-select-match placeholder="Select a person in the list or search his name/age...">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
        <div ng-bind-html="person.name | highlight: $select.search"></div>
    </ui-select-choices>

    <ui-select-static-choice ng-if="!$select.items.length">
        No results for <b>{{$select.search}}</b>
    </ui-select-choices-static>

    <ui-select-static-choice ng-if="$select.items.length<10">
        <button ng-click="fetchFromServer($select.search)">Search more results on server</button>
    </ui-select-choices-static>

  </ui-select>

dimirc avatar Aug 11 '14 03:08 dimirc

@ProLoser what do you think on this?

dimirc avatar Aug 14 '14 02:08 dimirc

It'd be really nice to specify if the ui-select-static-choice could appear above or below the search box, or tied to the bottom of the popup.

arkarkark avatar Aug 20 '14 21:08 arkarkark

@arkarkark maybe we could have a something like this:

<ui-select-static-choice anchor='bottom'>
        <button ng-click="openCreateNewWindow()">Create New</button>
</ui-select-choices-static>

dimirc avatar Aug 20 '14 22:08 dimirc

I don't know why, or exactly how the logic works now, but I sort of imagined something way less complicated:

<ui-select ...>
  ...
  <!-- this doesn't have to be ul+li, could be whatever DOM you wanted -->
  <ul ui-select-choices ...>
    <li ng-click="...">Static 1</li>
    <li ng-click="...">Static 2</li>
    <li ng-click="..." ng-repeat="...">...</li>
    <li ng-click="...">Static 3</li>
  </ul>
</ui-select>

I realize this may not be feasible based on the current design but this is essentially what I think about when I imagine static options mixed with virtual options. I am not a huge fan of creating more directives/attributes/options just for weird edgecases vs just making the level of control when templating much more powerful.

ProLoser avatar Aug 20 '14 22:08 ProLoser

@ProLoser I agree that more directives isn't something that I like neither. I'm only worried that if we change the functionality of ui-select-choices it will cause a big breaking change (also maybe this is the best time to introduce them).

Other alternative could be to leave the current implementation as a shortcut way (like other shortcuts proposed on https://github.com/angular-ui/ui-select/issues/106) and if user needs more flexibility, then they can use this other syntax with a child

  • declaration.
  • dimirc avatar Aug 20 '14 22:08 dimirc

    @dimirc I like your anchor="" choice.

    I see three options

    above_search below_search bottom

    once position: sticky is more supported, perhaps having those interleaved with the options would be really nice.

    https://youtu.be/O91_wFBR9bA

    while I'm wishing for a pony, having the static option scroll off when you scroll up (for position below_search or bottom), but then appear right away if you scroll down a bit (like the chrome url bar in android chrome (I think it's called quick return (like in this video: https://youtu.be/Qf8BgjfV3WU))

    arkarkark avatar Aug 20 '14 23:08 arkarkark

    Sorry but that exact level of convolution is what I would prefer to avoid. But I'm not the maintainer so it's only an opinion and the decision is up to you. I prefer using the dom structure for position and if you want fancy floating then add classes and customize the css in a separate file so you can keep updating the plugin.

    ProLoser avatar Aug 20 '14 23:08 ProLoser

    @arkarkark @ProLoser What do you think of the alternative I wrote on the previous comment:

    Other alternative could be to leave the current implementation as a shortcut way (like other shortcuts proposed on #106) and if user needs more flexibility, then they can use this other syntax with a child declaration.

    Basically we can still work the same way we are right now BUT if the user needs more flexibility then just add the repeat on a child element, to make it clear, these will be both valid:

    Valid way 1

     <ui-select ng-model="person.selected">
        <ui-select-match placeholder="Select a person...">{{$select.selected.name}}</ui-select-match>
        <ui-select-choices repeat="person in people |  filter:$select.search">
            {{person.name}}
        </ui-select-choices>
      </ui-select>
    

    Keeping support for this alternative, we have a smaller syntax on simple cases and also avoid introducing a breaking change.

    Valid way 2

     <ui-select ng-model="person.selected">
        <ui-select-match placeholder="Select a person...">{{$select.selected.name}}</ui-select-match>
        <ui-select-choices>
            <li repeat="person in people | filter:$select.search">{{person.name}}</li>
            <li>Static</li>
        </ui-select-choices>
      </ui-select>
    

    dimirc avatar Aug 20 '14 23:08 dimirc

    I agree with the confusion with the stuff I was asking for.

    the valid-way2 doesn't appear to support having something fixed in the window and not scrolling. I guess it'd be upto me to try and hack that up with position: fixed and some margins?

    arkarkark avatar Aug 21 '14 00:08 arkarkark

    @arkarkark

     <ui-select ng-model="person.selected">
        <ui-select-match placeholder="Select a person...">{{$select.selected.name}}</ui-select-match>
        <ui-select-choices>
           <li class="top">Sticky top</li>
            <li repeat="person in people | filter:$select.search">{{person.name}}</li>
            <li class="bottom">Sticky bottom</li>
        </ui-select-choices>
      </ui-select>
    
    .ul-select-choices {
      position: relative;
      padding: 30px 0;
    }
    .top, .bottom {
      position: absolute;
      left: 0;
      right: 0;
    }
    .top { top: 0; }
    .bottom { bottom: 0; }
    

    ProLoser avatar Aug 22 '14 03:08 ProLoser

    Nice! @ProLoser, thanks so much!

    arkarkark avatar Aug 24 '14 09:08 arkarkark

    Hi, I'm looking forward to this feature too!

    wkwwong avatar Sep 01 '14 02:09 wkwwong

    This would be really nice. Is there a current workaround to make this happen? @dimirc: is there a workaround for this that's possible now?

    dmackerman avatar Oct 01 '14 16:10 dmackerman

    Another way to ask this: is there ANY way to add static choices right now?

    dmackerman avatar Oct 06 '14 15:10 dmackerman

    I know this is way late but just saw your videos and I want to point out to people that I really don't advocate using this on mobile. Especially in the way you illustrated.

    ProLoser avatar Oct 06 '14 18:10 ProLoser

    @arkarkark

    ProLoser avatar Oct 06 '14 18:10 ProLoser

    +1 for this feature (using the bootstrap theme).

    FFelling avatar Dec 04 '14 11:12 FFelling

    Hi! It would be great to have such feature! Are there any valid ways to make a static element now?

    xSaber avatar Jan 06 '15 09:01 xSaber

    Any progress?

    piernik avatar Feb 04 '15 13:02 piernik

    Bump

    diosney avatar Feb 07 '15 22:02 diosney

    The only way that I've found to do this is to add a static choice to your data, and then just remove it when you're processing it for saving. Not ideal, but it does work...

    dmackerman avatar Feb 09 '15 16:02 dmackerman

    @dmackerman Thanks, that is what I'm doing now, but it could be good that pure static or mixed styles can be supported by the module.

    diosney avatar Feb 09 '15 16:02 diosney

    Any timeline?

    skhome avatar Mar 11 '15 13:03 skhome

    +1 is a useful feature

    rgevorkov avatar Mar 11 '15 13:03 rgevorkov

    I would appreciate this feature as well.

    jbaudisc avatar Mar 11 '15 16:03 jbaudisc

    After I finish with a refactor i'm working at https://github.com/angular-ui/ui-select/pull/731 , i'll start working on this issue

    dimirc avatar Mar 11 '15 20:03 dimirc

    I hope it will be possible to use only static entries too, like

    <ui-select ng-model="light.selected">
        <ui-select-match placeholder="Select a light color...">{{$select.selected.name}}</ui-select-match>
        <ui-select-choices>
           <li class="top">Red</li>
           <li class="top">Yellow</li>
           <li class="top">Green</li>
        </ui-select-choices>
      </ui-select>
    

    rgevorkov avatar Mar 12 '15 08:03 rgevorkov

    I'm looking forward to having it ;-)

    ahendel avatar Mar 12 '15 08:03 ahendel

    Whats the status on this?

    fforres avatar Apr 21 '15 16:04 fforres

    +1 on this feature

    jguillen avatar Apr 30 '15 18:04 jguillen