gpt4 book ai didi

angularjs - 重写 AngularJs DatePicker 弹出窗口以添加新标题

转载 作者:行者123 更新时间:2023-12-02 21:19:07 26 4
gpt4 key购买 nike

问题说明了一切。

我已经搜索了高低,但没有找到办法,但是,在我破解模板之前,我想我会在这里问。

只是为了说清楚 - 我希望能够在日期选择器的顶部添加一些文本(这是一个弹出窗口,如果这有什么区别的话),例如“你的生日是什么时候?”。

最佳答案

如果您关注此主题,有多种方法可以实现此目的:Can you override specific templates in AngularUI Bootstrap?但我只会限制两个,其中之一是 CSS。

模板覆盖:

Plunker Demo

弹出文件的默认文件是 template/datepicker/popup.html ,您只需复制文件的内容并向其附加新代码即可。新代码将被包装在 <script id="template/datepicker/popup.html" type="text/ng-template">directive并放置在<head>

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 '';
};
});

angular.module("template/alert/alert.html", []).run(["$templateCache",
function($templateCache) {
$templateCache.put("template/alert/alert.html",
" <div class='alert' ng-class='type && \"alert-\" + type'>\n" +
" <button ng-show='closeable' type='button' class='close' ng-click='close()'>Close</button>\n" +
" <div ng-transclude></div>\n" +
" </div>");
}
]);
.popup-header {
text-align: center;
font-weight: bold;
padding: 10px;
}
<!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">
<link href="style.css" rel="stylesheet">

<!-- Overriding code -->

<script id="template/datepicker/popup.html" type="text/ng-template">
<ul class="uib-datepicker-popup dropdown-menu" dropdown-nested ng-if="isOpen" style="display: block" ng-style="{top: position.top+'px', left: position.left+'px'}" ng-keydown="keydown($event)" ng-click="$event.stopPropagation()">
<!-- Extra code -->

<div class="popup-header">When is your Birthday?</div>

<!-- Extra code -->
<li ng-transclude></li>
<li ng-if="showButtonBar" style="padding:10px 9px 2px" class="uib-button-bar">
<span class="btn-group pull-left">
<button type="button" class="btn btn-sm btn-info uib-datepicker-current" ng-click="select('today')" ng-disabled="isDisabled('today')">{{ getText('current') }}</button>
<button type="button" class="btn btn-sm btn-danger uib-clear" ng-click="select(null)">{{ getText('clear') }}</button>
</span>
<button type="button" class="btn btn-sm btn-success pull-right uib-close" ng-click="close()">{{ getText('close') }}</button>
</li>
</ul>
</script>

<!-- Overriding code -->
</head>

<body>




<div ng-controller="DatepickerDemoCtrl">



<div class="row">
<div class="col-xs-offset-3 col-xs-6 col-md-3">
<h4 class="text-center">Date picker Popup</h4>
<p class="input-group">
<input type="text" class="form-control date-picker" 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" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>

</div>
</body>

</html>

CSS 编辑:

这是一种非标准方式,但它不会干扰您的模板结构。

Plunker Demo

:before CSS 中的伪元素支持 content属性来创建文本。由于您不需要添加除标题文本/标题之外的任何内容,因此这是一个合适的解决方案。检查style.css Plunkr 中的文件来编辑文本。

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 '';
};
});
.date-picker + .dropdown-menu::before {
content: "When is your Birthday?";
font-weight: bold;
position: relative;
left: 25%;
}
.date-picker + .dropdown-menu li {
margin-top: 5px;
}
<!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">
<link href="style.css" rel="stylesheet">
</head>

<body>

<div ng-controller="DatepickerDemoCtrl">



<div class="row">
<div class="col-xs-offset-3 col-xs-6 col-sm-offset-4 col-sm-4 col-md-3">
<h4 class="text-center">Date picker Popup</h4>
<p class="input-group">
<input type="text" class="form-control date-picker" 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" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>

</div>
</body>

</html>

关于angularjs - 重写 AngularJs DatePicker 弹出窗口以添加新标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33062543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com