Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Ionic Fancy Select Example</title>

<link href="http://code.ionicframework.com/1.3.1/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.3.1/js/ionic.bundle.min.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<!--<script src="cordova.js"></script>-->

<script src="src/ionic-fancy-select.js" type="text/javascript"></script>

</head>

<body ng-app="ionicApp">

<div ng-controller="MainCtrl">

<fancy-select
header-text="Select an option"
items="countries"
value="selected"
value-property="id"
text-property="id"
allow-empty='true'
multi-select="false"
text="{{countries_text_single}}"
value-changed="onValueChanged(value)"
get-custom-text="getCustomText(value)"
>
</fancy-select>

the selected value is {{selected}}
</div>

<script type="text/javascript">
angular.module('ionicApp', ['ionic', 'ionic-fancy-select'])
.controller('MainCtrl', function($scope)
{
$scope.countries = [
{id: 1, Name: 'USA', checked: false},
{id: 2, Name: 'France', checked: false},
{id: 3, Name: 'Japan', checked: true}];

$scope.countries_text_single = 'Choose country';
$scope.val = {single: null, multiple: null};
});

</script>

</body>
</html>
8 changes: 7 additions & 1 deletion src/ionic-fancy-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ angular.module("ionic-fancy-select", ["ionic"])

} else {
scope.modal = $ionicModal.fromTemplate(
'<ion-modal-view> <ion-header-bar class="bar-positive"> <button class="button button-positive button-icon ion-ios-arrow-back" ng-click="hideItems()"/> <h1 class="title">{{headerText}}</h1> <button class="button button-positive button-icon ion-checkmark" ng-show="multiSelect" ng-click="validate()"/> </ion-header-bar> <ion-content> <ion-list> <ion-item class="item-checkbox" ng-if="multiSelect" ng-repeat="item in items"> <label class="checkbox"> <input type="checkbox" ng-checked="item.checked" ng-model="item.checked"> </label>{{item.Name}}</ion-item> <label class="item" ng-click="validate(item)" ng-if="!multiSelect" ng-repeat="item in items">{{item.Name}}</label> </div></ion-content></ion-modal-view>',
'<ion-modal-view> <ion-header-bar class="bar-positive"> <button class="button button-positive button-icon ion-ios-arrow-back" ng-click="hideItems()"/> <h1 class="title">{{headerText}}</h1> <button class="button button-positive button-icon ion-checkmark" ng-if="multiSelect" ng-click="validate()"/> <button class="button button-positive button-icon ion-backspace" ng-if="!multiSelect && allowEmpty" ng-click="removeSelection()" /> </ion-header-bar> <ion-content> <ion-list> <ion-item class="item-checkbox" ng-if="multiSelect" ng-repeat="item in items"> <label class="checkbox"> <input type="checkbox" ng-checked="item.checked" ng-model="item.checked"> </label>{{item.Name}}</ion-item> <label class="item" ng-click="validate(item)" ng-if="!multiSelect" ng-repeat="item in items">{{item.Name}}</label> </div></ion-content></ion-modal-view>',
{
scope: scope,
animation: scope.modalAnimation
Expand Down Expand Up @@ -192,6 +192,12 @@ angular.module("ionic-fancy-select", ["ionic"])
scope.hideItems();
};

scope.removeSelection = function() {
scope.text = scope.defaultText;
delete scope.value;
scope.hideItems();
};

// Watch the value property, as this is used to build the text
scope.$watch(function(){return scope.value;}, scope.onValueChanged, true);
}
Expand Down
3 changes: 2 additions & 1 deletion templates/modal-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<ion-header-bar class="bar-positive">
<button class="button button-positive button-icon ion-ios-arrow-back" ng-click="hideItems()" />
<h1 class="title">{{headerText}}</h1>
<button class="button button-positive button-icon ion-checkmark" ng-show="multiSelect" ng-click="validate()" />
<button class="button button-positive button-icon ion-checkmark" ng-if="multiSelect" ng-click="validate()" />
<button class="button button-positive button-icon ion-backspace" ng-if="!multiSelect && allowEmpty" ng-click="removeSelection()" />
</ion-header-bar>

<ion-content>
Expand Down