|
| 1 | +<html ng-app="ionicApp"> |
| 2 | +<head> |
| 3 | + <meta charset="utf-8"> |
| 4 | + <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> |
| 5 | + |
| 6 | + <title>Radio Buttons</title> |
| 7 | + |
| 8 | + <link rel="stylesheet" href="../../dist/css/ionic.css"> |
| 9 | + <script src="../../../../dist/js/ionic.bundle.js"></script> |
| 10 | + <script> |
| 11 | +angular.module('ionic').directive('ionRadioFix', function() { |
| 12 | + return { |
| 13 | + restrict: 'E', |
| 14 | + replace: true, |
| 15 | + require: '?ngModel', |
| 16 | + transclude: true, |
| 17 | + template: |
| 18 | + '<label class="item item-radio">' + |
| 19 | + '<input type="radio" name="radio-group">' + |
| 20 | + '<div class="radio-content">' + |
| 21 | + '<div class="item-content disable-pointer-events" ng-transclude></div>' + |
| 22 | + '<i class="radio-icon disable-pointer-events icon ion-checkmark"></i>' + |
| 23 | + '</div>' + |
| 24 | + '</label>', |
| 25 | + |
| 26 | + compile: function(element, attr) { |
| 27 | + console.log('Custom radio running'); |
| 28 | + if (attr.icon) { |
| 29 | + var iconElm = element.find('i'); |
| 30 | + iconElm.removeClass('ion-checkmark').addClass(attr.icon); |
| 31 | + } |
| 32 | + |
| 33 | + var input = element.find('input'); |
| 34 | + angular.forEach({ |
| 35 | + 'name': attr.name, |
| 36 | + 'value': attr.value, |
| 37 | + 'disabled': attr.disabled, |
| 38 | + 'ng-value': attr.ngValue, |
| 39 | + 'ng-model': attr.ngModel, |
| 40 | + 'ng-disabled': attr.ngDisabled, |
| 41 | + 'ng-change': attr.ngChange, |
| 42 | + 'ng-required': attr.ngRequired, |
| 43 | + 'required': attr.required |
| 44 | + }, function(value, name) { |
| 45 | + if (angular.isDefined(value)) { |
| 46 | + input.attr(name, value); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + return function(scope, element, attr) { |
| 51 | + scope.getValue = function() { |
| 52 | + return scope.ngValue || attr.value; |
| 53 | + }; |
| 54 | + }; |
| 55 | + } |
| 56 | + }; |
| 57 | +}); |
| 58 | + </script> |
| 59 | + <style> |
| 60 | + |
| 61 | +.item-radio input:checked + .radio-content .item-content { |
| 62 | + /* style the item content when its checked */ |
| 63 | + background: #f7f7f7; |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + .item-radio input:checked + .radio-content .radio-icon { |
| 68 | + /* show the checkmark icon when its checked */ |
| 69 | + visibility: visible; |
| 70 | + |
| 71 | + } |
| 72 | + </style> |
| 73 | +</head> |
| 74 | + |
| 75 | +<body ng-controller="MainCtrl"> |
| 76 | + |
| 77 | +<ion-header-bar class="bar-positive"> |
| 78 | + <h1 class="title">Radio Buttons</h1> |
| 79 | +</ion-header-bar> |
| 80 | + |
| 81 | +<ion-content> |
| 82 | + {{ formData }} |
| 83 | + <div class="list"> |
| 84 | + <ion-radio-fix ng-model="formData.color" ng-value="'red'" name="color">Red</ion-radio-fix> |
| 85 | + <ion-radio-fix ng-model="formData.color" ng-value="'blue'" name="color">Blue</ion-radio-fix> |
| 86 | + <ion-radio-fix ng-model="formData.color" ng-value="'yellow'" name="color">Yellow</ion-radio-fix> |
| 87 | + </div> |
| 88 | +</ion-content> |
| 89 | +<script> |
| 90 | +angular.module('ionicApp', ['ionic']) |
| 91 | +.controller('MainCtrl', function($scope) { |
| 92 | + $scope.formData = {}; |
| 93 | +}); |
| 94 | +</script> |
| 95 | +</body> |
| 96 | +</html> |
0 commit comments