Git Product home page Git Product logo

oi.select's Introduction

#oi.select — AngularJS directive of select element

Download 0.2.22

Features

  • multiselect
  • API compatible with Angular select
  • Angular 1.2+ without jQuery and other dependencies
  • search options by substring (including the search query to the server)
  • use Bootstrap styles (but you can use own styles)
  • 17 KB minified

Demo

Do you want to see module in action? Visit tamtakoe.github.io/oi.select or try playground

Installation

You can download files through Bower:

npm install -g bower
bower install oi.select

or use npm:

npm install --save oi.select

or use local:

npm install
npm install -g bower
npm install -g gulp
bower install

run local:

gulp
open "http://localhost:3000"

make build and run tests:

gulp build
gulp test

Then you need to include into index.html:

select.min.css
select.min.js or select-tpls.min.js

When you are done downloading all the dependencies and project files the only remaining part is to add dependencies on the oi.select AngularJS module:

angular.module('myModule', ['oi.select']);

Use oi-select directive:

<oi-select
    oi-options="item.name for item in shopArr track by item.id"
    ng-model="bundle"
    multiple
    placeholder="Select"
    ></oi-select>

Attributes

oi-select directive

  • oi-options — see: ngOptions
    • oi-options="item for item in shopArrShort | limitTo: 3" — filter input list
    • oi-options="item for item in shopArrFn($query, $selectedAs)" — generate input list (expects array/object or promise)
  • ng-model — chosen item/items
  • ng-disabled — specifies that a drop-down list should be disabled
  • multiple — specifies that multiple options can be selected at once
  • multiple-limit — maximum number of options that can be selected at once
  • placeholder — native placeholder
  • multiple-placeholder — placeholder which is shown in multiple mode near chosen options
  • list-placeholder — placeholder which is shown in list if no elements found
  • readonly — specifies that an input field is read-only
  • autofocus — specifies that an input field should automatically get focus when the page loads
  • oi-select-options — object with options. You can override them in oiSelectProvider.options
    • debounce — timeout of debounced input field (default: 500). Set only if value is function which return promise
    • searchFilter — filter name for items in search field
    • dropdownFilter — filter name for items in dropdown
    • groupFilter — filter name for group header
    • listFilter — filter name for items order in dropdown. Use none to disable filtering. You can set special options (see Filtered example)
    • editItem — function which get lastQuery, removedItem and getLabel(item) and return string for input after element was removed (default: ''). editItem = true allows you to edit a deleted item. editItem = 'correct' same as true but does not edit the first time
    • saveTrigger — Trigger on which element is stored in the model. May be enter, blur, space, tab and any characters devided by spaces (default: enter tab blur)
    • cleanModel — Clean model on click for single select.
    • closeList — close dropdown list by default after choosing or removing item (default: true)
    • newItem — Mode of adding new items from query (default: false). May be autocomplete (priority save matches), prompt (priority save new item)
    • newItemModel — New items model (default: model = query). $query value from model will be changed to query string.
    • newItemFn — function which get query and return new item object or promise. F.e. 'addItem($query)'
    • removeItemFn — function which get removed item model and return any value or promise. If promise was rejected, item wouldn't removed. F.e. 'removeItem($item)'
    • maxlength — maximum number of characters allowed in the input
    • minlength — minimum number of characters for searching

oiSelect service

  • options — default options which we can override in oiSelectProvider.options
  • version — current version

oi.select's People

Contributors

alfonsoara avatar fenex avatar gmichalec-pandora avatar jimmytheneutrino avatar simong avatar tamtakoe avatar tandibar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oi.select's Issues

Проблема с пустым источником данных

В случае асинхронной загрузки данных, если на момент рендеринга компонента источник данных, указанный в oi-options отсутствует, возникает исключение:

Error: values is undefined
getMatches/timeoutPromise

function getMatches(query, selectedAs) {
var values = valuesFn(scope.$parent, {$query: query, $selectedAs: selectedAs}),
waitTime = 0;

    scope.selectorPosition = options.newItem === 'prompt' ? false : 0;

    if (!query && !selectedAs) {
            scope.oldQuery = null;
    }

    if (timeoutPromise && (values.$promise && !values.$resolved || angular.isFunction(values.then))) { <<<<<<< здесь тоже может быть
            $timeout.cancel(timeoutPromise); //cancel previous timeout
            waitTime = options.debounce;
    }

    timeoutPromise = $timeout(function() {
            scope.showLoader = true;

            return $q.when(values.$promise || values)  <<<<<<< здесь

Для воспроизведения ошибки достаточно указать в oi-options несуществующий источник данных.

Возможно, стоит активировать компонент (в т.ч. начинать слушать изменения модели и т.д.) только дождавшись появления в scope объекта-источника данных.

Just a sipmle fix for Bootstrap validation

Here rules I used to fix validation visual.
.has-success oi-select .select-search {
border-color: #3c763d;
}
.has-error oi-select .select-search {
border-color: #a94442;
}

oi.select 0.2.2 single selection doesn't update input value until blur event is executed

I'm using oi-select with single seleccion and the problem is the following:

Step-by-step:

  1. I click inside the input and oi-select shows me all options values.
  2. I click to select one option and oi-select hides options but keeps the placeholder string and doesn't update input value.
  3. I click outside the input (in any place) and the input loses focus and then the value is set

LimitTo doesn't work

I've filled options with 7 items. But showns only four items. I tried to set LimitTo 6, but it doesn't help me.

Save new item on "comma" (saveTrigger)

Currently it seems only 'enter' and 'blur' are available triggers to save new items. It would be great if new items could be saved on "comma" too.

Will try to build a custom directive for this, but wanted to check if anyone else had a solution already?

Urgent Tabbing away suggestions still showing

test
When I tab away after adding a new item it still shows .
Here is my code

$scope.addName = function (query) {
if (query && _.findIndex(scope.model.availableNamess, { description: query }) === -1) {
$scope.model.name = query;
return resource.addname($stateParams, $scope.model);
}
};
I have now change so only return one item but does not update list where as when I did not return and added item into list and it stayed in the box.

tabindex attribute isn't being removed correctly

First off, thank you for adding the tabindex attribute, it's exactly what we need.

There's a small bug however. When add tabindex="0" to the oi-select element and step through the code the input's field tabindex correctly gets its tabindex attribute set to 0 and the tabindex attribute on the oi-select element gets removed. However when I stop stepping through and just let the script resume it looks like tabindex="0" attribute added again to the oi-select field.

When you have the following source:

<input type="text" name="title" tabindex="1" /> <br />
<oi-multiselect tabindex="2" ... />
<input type="submit"  tabindex="3" />

it ends up (after full initialization) as:

<input type="text" name="title" tabindex="1" /> <br />
<oi-multiselect tabindex="0">
   ...
   <input type="text" tabindex="2" />
   ...
</oi-multiselect>
<input type="submit"  tabindex="3" />

So when you tab from the title field you end up focussing the oi-multiselect element and NOT the input field in the oi-multiselect

Remove item function

We have newItemFn callback but removeItemFn. I want to do something when removing an item.

Open options on 'focus'

It seems only 'click' events trigger the drop-down options list to open. Is there a way to make this open on 'focus'?

It would make it neater when you tab through forms where you rely on the options.

v 1.0.0

Rename oi.select to oi-select(bower), to oiSelect(angular module), rename select-* to oiselect-* in styles

Failed to execute 'requestAnimationFrame' on 'Window': The callback provided as parameter 1 is not a function.

angular v1.2.26
oi.select full: '0.2.15',

TypeError: Failed to execute 'requestAnimationFrame' on 'Window': The callback provided as parameter 1 is not a function.
    at TypeError (native)
    at http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:11860:20
    at http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4344:31
    at async (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4179:13)
    at Object.$provide.$get.fn.removeClass (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4311:9)
    at Object.fn (http://localhost:63342/TF-API/Client-UI/src/jslibs/select/select-tpls.js:545:69)
    at Scope.promises.$get.Scope.$digest (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:12541:29)
    at Scope.promises.$get.Scope.$apply (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:12806:24)
    at http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:14314:36
    at completeOutstandingRequest (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4397:10)(anonymous function) @ angular.js:10072str2.$get @ angular.js:7364promises.$get.Scope.$digest @ angular.js:12560promises.$get.Scope.$apply @ angular.js:12806(anonymous function) @ angular.js:14314completeOutstandingRequest @ angular.js:4397(anonymous function) @ angular.js:4705
angular.js:10072 TypeError: Failed to execute 'requestAnimationFrame' on 'Window': The callback provided as parameter 1 is not a function.
    at TypeError (native)
    at http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:11860:20
    at http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4344:31
    at async (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4179:13)
    at Object.$provide.$get.fn.removeClass (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4311:9)
    at Object.fn (http://localhost:63342/TF-API/Client-UI/src/jslibs/select/select-tpls.js:551:66)
    at Scope.promises.$get.Scope.$digest (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:12541:29)
    at Scope.promises.$get.Scope.$apply (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:12806:24)
    at http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:14314:36
    at completeOutstandingRequest (http://localhost:63342/TF-API/Client-UI/src/jslibs/angular.js:4397:10)(anonymous function) @ angular.js:10072str2.$get @ angular.js:7364promises.$get.Scope.$digest @ angular.js:12560promises.$get.Scope.$apply @ angular.js:12806(anonymous function) @ angular.js:14314completeOutstandingRequest @ angular.js:4397(anonymous function) @ angular.js:4705
'''

Using function to translate selection texts

Hi,

I am using the following module to translate our application:
https://angular-gettext.rocketeer.be/

It seems to work in all other cases but when I try to translate ng-options for oi.select.

For example this works fine:

<select class="form-control form-input-select" ng-model="testData.test" ng-options="translate(t.name) group by translate(t.group) for t in trainings | orderBy:['group','name']" ng-change="selectedTest(testData.test)">
<option value="" translate>-- Select test --</option>
</select>

But this fails to print the translated text but prints an empty list item:

<oi-multiselect
ng-model="selectedTests" 
ng-options="translate(item.name) group by translate(item.group) for (key, item) in tests"
name="tests"
multiple
placeholder="{{'Add new'|translate}}"
required
></oi-multiselect>

I don't get any errors in console.log.

Issues with version 0.2.8

I just upgraded from oi.multiselect 0.1.7 to oi.select 0.2.8.

I noticed that there are a few weird things in the version.

  1. When selecting multiple values, the select box closes after each click which did not happen earlier. This makes selecting multiple values very slow.
  2. It seems that it does not register clicks everytime. I was able to reproduce this also with the demo http://tamtakoe.github.io/oi.select/#/select/#multiple with Google Chrome. When I click on different values I randomly have to click twice to add the selection.

Error loading multiple dropdowns in same view?

I getting a error every time I try to load more than one dropdown in my view.
Why this is happening exactly?

multiple-dropdowns

Here is the code related to print above:

<div class="col-xs-6">
    <label class="control-label">Test1</label>
    <oi-multiselect 
                    ng-options="testOne.Name for testOne in testOneDrop track by testOne.Id" 
                    ng-model="testOne" 
                    multiple></oi-multiselect>
</div>
<div class="col-xs-6">
    <label class="control-label">Test2</label>
    <oi-multiselect
                    ng-options="testTwo.Name for testTwo in testTwoDrop track by testTwo.Id" 
                    ng-model="testTwo" 
                    multiple></oi-multiselect>       
</div>

Call function in ng-options / io-options

I would like to call a function within the ng-options parameter. This works with regular select but not with ng-multiselect / io-select:

ng-options="item as myGeTextMethod(item) for item in items"

remove default model

Rename saveLastQuery to editItem and add option correct for editing item which you chose, but remove original model

How to remove drop-down options (leave oi-options blank)?

What would be the best way to only use oi-select for adding new items? I.e. not show the drop-down options at all.

Setting oi-options="null" or "false" clearly does not work.

Making oi.select work with only new items would omit my need to use ng-tags-input.

PS: Thanks for a great project!

Improve select field (comfortable work on mobile devices)

Possible to ask for a future enhancement to be able to hide the search field and only allow drop-down selection?

Context: My app only wants users to be able to select among the pre-defined options. And since it's just a few options to choose from, the search bar adds unnecessary complexity. Therefore I'd like to hide the search bar - thus make it behave more like a native select field - but still allow multi-select (i.e. selected options would be added as tags).

notempty attribute allows empty

Using the following declaration I was hoping to prevent from having an empty list of items.

oi-multiselect(
    ng-options="..."
    ng-model="..."
    multiple
    readonly
    notempty)

However I can remove all items. Is this not how the notempty attribute works?

Добавить возможность подписываться на событие blur на элементе мультиселекта

Было бы круто, если при потере фокуса внутренним инпутом на элементе вызывалось событие blur.
Сейчас есть функция blurHandler, которая срабатывает при закрытии выпадающего списка с подсказками. Но если подсказок нет, и мы снимаем фокус по клику вне элемента, либо по tab, то эта функция не вызывается.

How to add new item to io.select with custom oi-options?

I've used this io-options
oi-options="item.name for item in ciFilterController.filters track by item.id"

When I type new item and press enter I'll have this
http://prntscr.com/8riubh

Do you know how to fix it?
I use this ciFilterController.filters object

[{"id":"PENDING_CHANGES","name":"Pending Changes"},{"id":"LAST_WEEK","name":"Changes as of Last Week"},{"id":"LAST_MONTH","name":"Changes as of Last Month"},{"id":"NEW_FEATURES","name":"New Features from Release"}]

При открытии выпадающего списка очищается модель.

Ситуация:
На директиве висит валидация на заполненость модели.
Выбираю значение из выпадающего списка - модель заполнилась, фокус сбросился.
Повторно кликаю в поле ввода - открывается выпадающий список, но при этом очищается значение модели, и срабатывает валидация. Хотя данные в инпуте не изменились.

Make "multiple" attribute true/false

It would be extremely useful if the "multiple" attribute could be set dynamically to true or false, so that you could allow users to enable/disable multi select. E.g.

<oi-select
   ng-required="customOption.required"
   multiple="customOption.multiple"
   oi-options="option for option in options track by option"
   ng-model="customOption"
></oi-select>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.