bleyk
bleyk

Reputation: 799

Calendar icon angularjs

I have my design and I want to put the calendar Icon inside the input field of the datepicker instead of an arrow pointing down. How can I possibly do this? Thanks for any help :)

enter image description here

here's my code

  <label>
            <p>
                <input
                    type="date"
                    ng-disabled="isCheckboxSelected('1')"
                    id="test"
                    name="date"
                    ng-model="ngModel"
                    popup="d MMM yyyy"
                    options="dateOptions"
                    ng-click="Opened=true"
                    ng-change="saveNew()"
                    custom-datepicker="custom-datepicker "/>
                     <span class="calendar"></span>&nbsp; 

            </p>
        </label>
        <script type="text/ng-template" id="custom-datepicker.html">
            <div class="form-inline enhanced-datepicker">
                <label>
                    <input
                        type="text"
                        id="{{id}}"
                        name="{{name}}"
                        ng-model="ngModel"
                        datepicker-popup="{{popup}}"
                        datepicker-options="{{options}}"
                        date-disabled="{{dateDisabled}}"
                        min="{{min}}"
                        max="{{max}}"
                        open="opened"
                        ng-pattern="/^(?:[1-9]|1\d|2\d|3[0-1]) (?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) (?:1|2)(?:\d{3})$/gim"/>

                    <i ><span class="calendar"></span></i>&nbsp; 

                </label>
            </div>
        </script>
        <script>

Upvotes: 0

Views: 2366

Answers (1)

beaver
beaver

Reputation: 17647

Here is a snippet based on UI Bootstrap:

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) {
  $scope.today = function() {
    $scope.dt = new Date();
  };
  $scope.today();

  $scope.clear = function () {
    $scope.dt = null;
  };

  // Disable weekend selection
  $scope.disabled = function(date, mode) {
    return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
  };

  $scope.toggleMin = function() {
    $scope.minDate = $scope.minDate ? null : new Date();
  };
  $scope.toggleMin();
  $scope.maxDate = new Date(2020, 5, 22);

  $scope.open = function($event) {
    $scope.status.opened = true;
  };

  $scope.setDate = function(year, month, day) {
    $scope.dt = new Date(year, month, day);
  };

  $scope.dateOptions = {
    formatYear: 'yy',
    startingDay: 1
  };

  $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
  $scope.format = $scope.formats[0];

  $scope.status = {
    opened: false
  };

  var tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  var afterTomorrow = new Date();
  afterTomorrow.setDate(tomorrow.getDate() + 2);
  $scope.events =
    [
      {
        date: tomorrow,
        status: 'full'
      },
      {
        date: afterTomorrow,
        status: 'partially'
      }
    ];

  $scope.getDayClass = function(date, mode) {
    if (mode === 'day') {
      var dayToCheck = new Date(date).setHours(0,0,0,0);

      for (var i=0;i<$scope.events.length;i++){
        var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);

        if (dayToCheck === currentDay) {
          return $scope.events[i].status;
        }
      }
    }

    return '';
  };
});
<!doctype html>
<html ng-app="ui.bootstrap.demo">

<head>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
  <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
  <script src="example.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

  <style>
    .full button span {
      background-color: limegreen;
      border-radius: 32px;
      color: black;
    }
    
    .partially button span {
      background-color: orange;
      border-radius: 32px;
      color: black;
    }
    
    button.custom-cal {
      border-left: none;
    }
    
    input.custom-cal {
      border-right: none;
    }
  </style>
  <div ng-controller="DatepickerDemoCtrl">
    <pre>Selected date is: <em>{{dt | date:'fullDate' }}</em></pre>

    <h4>Popup</h4>
    <div class="row">
      <div class="col-md-6">
        <p class="input-group">
          <input type="text" class="form-control custom-cal" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="status.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close"
          />
          <span class="input-group-btn">
                <button type="button" class="btn btn-default custom-cal" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
              </span>
        </p>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6">
        <label>Format:</label>
        <select class="form-control" ng-model="format" ng-options="f for f in formats">
          <option></option>
        </select>
      </div>
    </div>

    <hr />
    <button type="button" class="btn btn-sm btn-info" ng-click="today()">Today</button>
    <button type="button" class="btn btn-sm btn-default" ng-click="setDate(2009, 7, 24)">2009-08-24</button>
    <button type="button" class="btn btn-sm btn-danger" ng-click="clear()">Clear</button>
    <button type="button" class="btn btn-sm btn-default" ng-click="toggleMin()" uib-tooltip="After today restriction">Min date</button>
  </div>
</body>

</html>

Upvotes: 1

Related Questions