GithubHelp home page GithubHelp logo

inmagik / ionic-modal-select Goto Github PK

View Code? Open in Web Editor NEW
174.0 7.0 70.0 6.67 MB

Modal select for Ionic Framework

Home Page: https://inmagik.github.io/ionic-modal-select

License: MIT License

JavaScript 76.74% HTML 23.26%

ionic-modal-select's Introduction

ionic-modal-select

Modal select for Ionic Framework based on $ionicModal

See all docs and examples on the project site.

We also have a simple Codepen demo.

animated example

IMPORTANT NOTICE

In order to survive, this project needs:

Any help on this is greatly appreciated. Comment directly those issues or contact me directly at mauro.bianchi at inmagik.com if you are interested in helping with this.

Features

  • supports long list of object via collection-repeat
  • optional search bar
  • supports unsetting the chosen value (optional)
  • customizable modal classes, modal header and footer classes
  • customizable buttons text
  • multiple selectable options (experimental)

Usage

Get the files from github or install from bower:

bower install ionic-modal-select

Include ionic-modal-select.js or its minified version in your index.html:

<script src="lib/ionic-modal-select/dist/ionic-modal-select.js"></script>

Add the module ionic-modal-select to your application dependencies:

angular.module('starter', ['ionic', 'ionic-modal-select'])

And you're ready to go.

Directives

modal-select

This directive will transform the element into a modal select: when clicking the element a select dialog will be open, with options presented in a clickable list. Once the user clicks on an option, it will be set on the bound model.

For this to work the following conditions must apply:

  • The element you use this directive must be clickable.
  • The directive requires ngModel to be set on the element
  • The directive expects an inner element of class "option" to define the options template

The final value bound to your model will be determined as follow:

  • if you set the attribute option-getter will be set as getterFunction(selectedItem)
  • if you set the attribute option-property will be set as selectedItem[propertyName]
  • otherwise it will be set as the full object

In case of "multiple" selection mode, the user is allowed to select multiple options and the bound ng-model will be a list containing the selected options, with the same logic of getting the value.

Options

option meaning accepted values default
options List of options to choose from Array
options-expression The expression indicating how to enumerate a the options collection, of the format variable in expression – where variable is the user defined loop variable and expression is a scope expression giving the collection to enumerate. For example: `album in artist.albums or album in artist.albums orderBy:'name'`. expression
option-getter Optional method to get the value from the chosen item function not set
option-property Optional property name to get as model value from the chosen item string not set
multiple If set (to any value) enables "multiple" selection mode that allows the user to select more than one option. For each option, a checkbox will be rendered. This feature is still experimental. string not set
modal-class The class for the modal (set on <ion-modal-view> string ''
selected-class The class applied to the currently selected option (if any) in the modal list string 'option-selected'
on-select Callback triggered on object select. Takes two arguments, newValue and oldValue with obvious meaning. function call with arguments newValue and oldValue not set
on-reset Callback triggered when value is resetted using the relevant ui interface. Takes no arguments. function call not set
on-close Callback triggered when modal is closed (in any way, uses 'modal.hidden' ionic event). Takes no arguments. function call not set
modal-title The title shown on the modal header string 'Select an option'
header-footer-class The class for header and footer of the modal string 'bar-stable'
cancel-button Text of the button for closing the modal without changing the value string 'Cancel'
reset-button Text of the button for unsetting value in the modal dialog string 'Reset'
ok-button Text of the button to accept the multiple selection. Appears only when multiple true. string 'Cancel'
hide-reset Hides the button for unsetting value in the modal dialog string. Set to 'true' for hiding the button false
use-collection-repeat Forces use of collection-repeat or ng-repeat for rendering options in the modal. string "true", "false" not set (automatically set according to number of options and short-list-break attribute)
short-list-break The maximum number of item in list to be rendered with ng-repeat.(if use-collection-repeat is not set) If the list has a number of options greater than this attribute it will be rendered with ionic collection-repeat directive instead. (see also load-list-message option) integer 10
load-list-message Message to be shown when loading a long list of options in the modal string 'Loading'
has-search Whether to show a search bar to filter options. set to "true" for showing the search bar undefined
search-placeholder String placeholder in search bar. string 'Search'
sub-header-class Class to be applied to the subheader containing the search bar (makes sense only if has-search="true) string 'bar-stable'
cancel-search-button Text for the button for clearing search text (makes sense only if has-search="true) string 'Clear'
clear-search-on-select Tells the directive to not clear the search bar content after user selection. Set to false to prevent clearing the search text. boolean true
search-properties Array of properties for the search. For example: In your controller $scope.searchProperties = ['property1', 'property2']; and in template attributes search-properties="searchProperties" Array

Passing in options

The modal-select directive must be provided with a set of options to choose from

This can be done in two ways:

  • via the options attribute, that accepts an array of values or objects. The directive will watch for changes in this array and modify its options accordingly.
  • via the options-expression attribute, that accepts an expression similar to what you would use with ionic collection-repeat directive, of the format variable in expression – where variable is the user defined loop variable and expression is a scope expression giving the collection to enumerate. For example: album in artist.albums or album in artist.albums | orderBy:'name'. This allows you to apply ordering or filtering without acting on the original array.

Options templates

This directive expects to find a single inner element of class "option" that is used to define the template of the options that can be selected. Options will be rendered as items into a list in the modal (The content of each option, rendered with your template, is wrapped in an element of class 'item item-text wrap' and the original ".option" element is removed).

For example:

<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a number">
    Select it
    <div class="option">
        {{option}}
    </div>
</button>

Will be rendered in the modal as :

<div class="item item-text-wrap">
    {{option}}
</div>

Multiple selection mode

From version 1.3.1, setting multiple attribute to any value other than "undefined" will enable the multiple selection on the widget. In this case, the user is allowed to select more than one option and options will be rendered with checkboxes in the selection modal. This feature is still experimental.

Search bar

From version 1.1.0 you can include a search bar into the modal for filtering options by simply adding the attribute has-search="true" to your modal-select element.

Filtering is implemented with the angular filter filter, which searches recursively in all properties of the objects passed in as options. This means that you cannot search on "computed properties" right now. For example if you are using a custom setter you will be only able to search the original properties of the options.

### Examples

Simplest one.

This example shows a modal for choosing a number between 1 and 5.

In your controller:

$scope.selectables = [1,2,3,4,5];

In your template:

<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a number">
    Select it
    <div class="option">
        {{option}}
    </div>
</button>

Including a search bar

To include a search bar in the previous example, just add has-search="true":

<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a number" has-search="true">
    Select it
    <div class="option">
        {{option}}
    </div>
</button>

Objects as options

In the following example we use some objects as options.

In your controller:

$scope.selectables = [
    { name: "Mauro", role : "navigator"},
    { name: "Silvia", role : "chef"},
    { name: "Merlino", role : "canaglia"}
];

We'll explore different possibilities we have with this options.

1. Setting the full object

If we do not set option-getter or option-property attributes, the model is assigned to the full option object when an option is selected.

<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a character">
    Select it
    <div class="option">
        {{option.name}} ({{option.role}})
    </div>
</button>
2. Setting a property

If option-property attribute is set to a string, the bound model assigned that property of the option object when an option is selected. For example if we set option-getter="name", we get back the 'name' property of our options.

<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a character" option-property="name">
    Select it
    <div class="option">
        {{option.name}} ({{option.role}})
    </div>
</button>
3. Custom setter

If a function call is passed via option-getter attribute, the bound model assignment is done by calling this function with the selected option as the only argument (named 'option'). For example if we do this in our controller:

$scope.getOption = function(option){
    return option.name + ":" + option.role;
};
<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a character" option-getter="getOption(option)">
    Select it
    <div class="option">
        {{option.name}} ({{option.role}})
    </div>
</button>
4. Specify the properties for search

Specify in the array the properties' name for search $scope.search_properties = ['propertie_1', 'propertie_2', '...'];:

$scope.search_properties = ['name'];
<button class="button button-positive" modal-select ng-model="someModel" options="selectables" modal-title="Select a character" option-getter="getOption(option)" search-properties="search_properties">
    Select it
    <div class="option">
        {{option.name}} ({{option.role}})
    </div>
</button>

We get back the phrase "Mauro:navigator", "Silvia:chef" or "Merlino:canaglia" if we click the previous defined options.

More examples on the project site.

Maintenance and support

This project is maintained by INMAGIK.

ionic-modal-select's People

Contributors

bianchimro avatar danielpflood avatar elchuz avatar leoruhland avatar lucasdealmeida avatar meanme avatar nazrdogan avatar philcorcoran avatar sikandarg avatar swaheed2 avatar vuk-nikolic 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

ionic-modal-select's Issues

Search on Firebase $id

Hi,
I've a strange issue when loading data from firebase. Both example below are displaying the same but I need to use the first one.

If I do:
<button ng-change="selectChange()" modal-select hide-reset="true options-expression="cit in city" header-footer-class="bar-positive" has-search="true" modal-title="In which city are you ?" sub-header-class="bar-calm"> <div class="option">{{option.$id}}</div> </button>

The search is not functioning.

While if I do:
<button ng-change="selectChange()" modal-select hide-reset="true options-expression="cit in city" header-footer-class="bar-positive" has-search="true" modal-title="In which city are you ?" sub-header-class="bar-calm"> <div class="option">{{option.name}}</div> </button>

It's working!
Any idea how I can make it work with $id has search criteria?

support set option item class

sometimes we want display some option items with other class, e.g. disabled, and which is unselectable, but current implement does not allow us to do that.

iPad rendering

Hi, it seems on iPad, the max height and max width is capped to some values, thus the new view rendering all the select option is displayed smaller than the actual iPad size..
Any idea on how to remove those max values?

Thanks

has no method 'remove'

Error log

TypeError: Object #<HTMLDivElement> has no method 'remove' at link (file:///android_asset/www/lib/ionic-modal-select/dist/ionic-modal-select.js:120:17)

Won't load on older devices.

search & scroll

2016-02-05 2

Sorry for my bad english
Example:
Long list of numbers (1 ... 99)
If at first to scroll to end array (ex. 99) and then select a search (ex. 1), the result is not placed at the beginning of the selected values (1, 10, 11 etc).

refactor docs

Keep api close to examples (single section),
keep the division used for examples.

Multiple buttons each associated with a modal

Hi,
Thanks for the nice plugin.. I'm trying to use it to show a modal on click of a button. The page has multiple rows and columns of buttons. The issue is, the page hangs for sometime after all the buttons show up. And then it works as expected. Is there a way to optimize or remove this initial freeze? Or is it possible to use a single modal for all the buttons? Any help is appreciated. The view markup is as below,

<ul class="h-list" ng-repeat="row in rows" style="clear:both;width:{{cols.length  * 54}}px;">
                <li ng-repeat="col in cols">
                    <div class="seat" 
                         ng-repeat="seat in seatlayout| filter: {SeatRow: row.toString(), SeatColumn: col.toString()} : true">
                        <button 
                             ng-if="getSeatStatusClass(seat) === 'seat_free'"
                             class="seat"
                             ng-class="getSeatStatusClass(seat)"
                             ng-click="toggleSeat(seat)"
                             modal-select=""
                             ng-model="selTicketType[seat.Id]" options= "tickettypes" 
                             modal-title="Select Ticket Type" on-select="buildSelectedSeats(newValue)" >
                            {{seat.SeatNo}}
                            <div class="option">
                                {{option.TicketTypeName}} - {{option.TotalTicketPrice}}
                            </div>
                        </button>
                        <button 
                                ng-if="getSeatStatusClass(seat) !== 'seat_free'"
                                class="seat"
                                ng-class="getSeatStatusClass(seat)"
                                ng-click="toggleSeat(seat)">
                            {{seat.SeatNo}}
                        </button>

                        <button ng-show="seatlayout.length==0" class="seat">&nbsp;</button>
                    </div>
                </li>
            </ul>

option-getter not working

Hello!
I have :

JS

 $scope.selected = function(Name){
            console.log(Name);
        };

and HTML

<div class="item item-body" ng-if="items">
            <button class="button button-dark" modal-select="" ng-model="selectedname"  option-getter="selected(Name)"
                    options="items"  modal-title="Alege locatia">
               Alege
                <div class="option">
                    <a ng-click="numeales=option.name" class="item item-thumbnail-left">
                        <img ng-src="{{ option.picture }}">
                        <h2>{{option.name}}</h2>
                    </a>
                </div>
            </button>
        </div>
        <div ng-if="numeales" class="item">
           Selected option: {{selectedname}}
        </div>

I have 3 elements in array, but when I click on select to open modal, console.log gives me 9 objects, and when I select an element, {{selectedname}} does not update.

Directive option with FireBase

Hello,
If I use a firebase object, nothing is displayed on the modal but if the same variable is hardcoded, the modal display works fine.
Any idea ?

Thanks for your help,
Marc

HTML:

<button class="button button-positive" modal-select ng-model="selectedBoat" options="boats" modal-title="Search a boat"
    has-search="true" >
      Add a boat
      <div class="option">
        <span ng-bind-html="option.BoatName"></span>
        <small ng-bind-html="option.Immatriculation"></small>
      </div>
</button>

Controller with Dynamic Variable:

angular.module('App')
.controller('HandicappedCtrl', function ($scope,$http,$ionicModal,BOATS) {
$scope.selectedBoat = null;
$scope.boats = BOATS;

})
.factory("BOATS", function($firebaseArray) {
  var boatsRef = new Firebase("https://MYAPP.firebaseio.com/srs");
  return $firebaseArray(boatsRef);
})

Hardcoded variable:

$scope.boats = [ {
  "BoatName" : "Alivys",
  "CCR" : 328,
  "Classe" : "TCF3",
  "Club" : "SNMC",
  "Country" : "SUI",
  "FirstName" : "georges",
  "Immatriculation" : "VD 9081",
  "LastName" : "wagner",
  "MultiHull" : "Non",
  "NoSrs" : 365,
  "Region" : "ACVL",
  "SailNo" : 339,
  "Serie" : "Oui",
  "TCF" : 1.005,
  "Type" : "First Class 8"
}, {
  "BoatName" : "Joyeuse",
  "CCR" : 298,
  "Classe" : "TCF4",
  "Club" : "CVL",
  "Country" : "SUI",
  "FirstName" : "Gilles",
  "Immatriculation" : "VD 5557",
  "LastName" : "Favre",
  "MultiHull" : "Non",
  "NoSrs" : 418,
  "Region" : "ACVL",
  "SailNo" : 17,
  "Serie" : "Non",
  "TCF" : 0.998,
  "Type" : "6 m (ancienne jauge)"
}];

Mention how to fix search with firebase $id

Using search and firebase $id causes some problems unless the attribute search-properties is set and contains $id .
This should be mentioned in README and docs, as many ionic users are firebase users.

see #41

Create NPM package

We are currently only using npm and not bower. Can you please make an NPM package for this library in addition to the bower one?

button submit the form by default

Hello,
very helpful plugin and easy to use.
There is a problem that the form is submitted directly after we click the button that open modal, so you need to add type="button" to the button attribute in order to solve this problem.

Thanks.

option-getter is called many many times

The option-getter callback is not called once when the user choose the option, but many times both when opening modal and when selecting.

This issue is present in the codepen sample, too.

ionic icon in modal select

Hi, is that possible to have an icon list in ionic-modal-select? I want to create a list of activity, thus I'll associate one icon for each.

Thanks

Two fancy selects on same page with search

I was able to add 2 select drop downs on a single page. However, if I add the search functionality and search by text, the second dropdown shows only the options that matched the search text for first option in the drop down.

on-select returns undefined

Hello!
I have :

JS

 $scope.selected = function(New, Old){
            console.log(NeW + ' and ' + Old);
        };

and HTML

<div class="item item-body" ng-if="items">
            <button class="button button-dark" modal-select="" ng-model="selectedname"  on-select="selected(New,Old)"
                    options="items"  modal-title="Alege locatia">
               Alege
                <div class="option">
                    <a ng-click="numeales=option.name" class="item item-thumbnail-left">
                        <img ng-src="{{ option.picture }}">
                        <h2>{{option.name}}</h2>
                    </a>
                </div>
            </button>
        </div>
        <div ng-if="numeales" class="item">
           Selected option: {{selectedname}}
        </div>

And I receiving undefined on function call. - both parameters

Multiple Choices

Hi,

this really a great plugin, but i can't figure out how to choose more than one options without closing the modal.

mousewheel

mouse wheel does not work (scroll long list) in firefox

Unable to populate if the data is comming from webapi

Hi, I have following code, to get data from api and then set in list.

` $http.get(sharedProperties.getURLOfLanguagesWebAPI()).then(function (data) {

        allData = sharedProperties.convertXml2JSon(data.data);

        for (var i = 0; i < allData.OVRLookupData.Languages.length; i++) {
            $scope.languages.push({ "id": parseInt(allData.OVRLookupData.Languages[i].LanguageCode), "name": allData.OVRLookupData.Languages[i].Language });
        }

        $scope.loadingLangues = false;

    }, function (data) {
        console.log(data);
    });`

HTML is like:
<label name="Language" class="item item-selectbox"> <span class="input-label" style="float:left">Select Language</span> <button class="button button-dark button-outline icon-right ion-arrow-down-b" modal-select ng-model="selectedValue" options="languages" on-select="languageChange(newValue)" modal-title="Select Language"> {{ selectedValue.name || &apos;Select Language&apos;}} <div class="option">{{option.name}}</div> </button> </label>

If I print in html like {{languages}} then I can see the values. However, the select box shows empty list.

Is it possible to populate values via api call?

Open another modal on selection

Hi I really like your directive, but I would like a multi select feature o support to trigger a new modal from the controller(for example, inside the on-select callback)

Selected value callback

Hi, great directive, just one question. If i want to do certain action when one of the options is selected, how can i do it? It seems i only have the option to manually watch the model.

not scrolling to selected value

It should scroll to selected value if there are selected value.
Eg: selection of year, if the options is from year 1900 to 2100, user would need to scroll to the bottom to select year 2000 every time user opens the modal.

Use on <select>

The documentation states

The element you use this directive must be clickable.

any chance we could get this to work for a tag or are there any technical limitations why this is not possible?

Seeking co-mantainers

Hi guys,
anyone is interested in being a co-maintainer of this module?

I don't have much time to work on it at the moment, and there is some amount of planned work and opened issues right now.

regards
Mauro

modal-select tests: help wanted!

The situation about tests is the following:

  • Testing environment has been setup with gulp and karma
  • Only tests for the compile directive have been added (in tests/compile-directive.tests.js)
  • The rest of the project completely lacks tests

I've put some effort in trying to write tests for the main modal-select directive, but couldn't get to a good solution about testing the code.
Sadly, this reflects my poor experience with testing of js code of a component like this one. This case, in particular, is hard to handle for me for the followin reason: It's not very clear to me how to test the component without user interaction, as it has very strong dependencies on some ionic directives and services such as $ionicModalSelect and collection-repeat

Anyone can help on this?

Selected value by default

Hi, amazing job.
Just a issue I have with a value I want to select by default, am I supposed to use selected-class ?
If yes, how to use it?

Thanks vm

option render problem

yes, we can use

<div class="option">
  {{option}}
</div>

or

<div class="option">
  {{option.propertyName}}
</div>

But, when I try this:

<div class="option">
  {{theScopeFunction(option)}}
</div>

the function always got undefined as the parameter.

Modal select opened from popup

Hi,
I got a new issue today while I was trying to open a modal select view from a popup.. The view stay behind the popup meaning that I can still interact with it but the view is greyed and I was hopping the view to be forward..

This css trick didn't really help
.popup-open .backdrop { z-index: 11; }

Selected option in template

Using <div class="option">{{option....}}</div> one can access all properties of option to build the selection list display.

One can also use option-property or option-getter to get/build the ngModel value.
But then, one can't get a handle on the selected option.

It would be nice to have the selected option, if any, available in scope inside the directive so one can build a proper display of the selected option out of the modal.

Something like:

<some-element modal-select
      ng-model="myModel.someRelationship
      options="myOptions"
      option-property="id">
  <div class="option">{{option.firstName}} {{option.lastName}}</div>
  <div ng-if="!myModel.someRelationship">Please select something</div>
  <div ng-if="myModel.someRelationship">{{selected.firstName}} {{selected.lastName}}</div>
</some-element>

What do you think?

clear search bar after selection

After selecting an option, probably the search bar should be cleared.
We could make this behavior an opt-in or an opt-out by setting some attibute (for example clear-search-bar

Bower registry not getting the most recent version

Don't know if I'm doing this wrong, but I'm doing bower install ionic-modal-select and it downloads the the 1.1.2 version while I think it should download the 1.2 version.
I even tried to force to install the 1.2 but it couldn't find it.

$ bower install ionic-modal-select#1.2
bower not-cached    git://github.com/inmagik/ionic-modal-select.git#1.2
bower resolve       git://github.com/inmagik/ionic-modal-select.git#1.2
bower ENORESTARGET  No tag found that was able to satisfy 1.2

Additional error details:
Available versions in git://github.com/inmagik/ionic-modal-select.git: 1.1.2, 1.1.1, 1.1.0, 1.0.0

I decided to install it using the git url, pointing to the master branch, like so:
$ bower install https://github.com/inmagik/ionic-modal-select.git#master

Why both js and min js are in bower

Now it is :
"main": [
"dist/ionic-modal-select.js",
"dist/ionic-modal-select.min.js"
],

I use wiredep, that setting causes the both js files are included in my index.html.

Search bar

Add options to insert a search bar to filter available options

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.