我有一个连接成角形的表格,用于验证。我可以使用ng-show指令显示错误消息,如下所示:
<span ng-show="t3.f.needsAttention(f.fieldName)" ng-cloak>
<span ng-show="f.fieldName.$error.required && !f.fieldName.$viewValue">
This field is required.
</span>
</span>
..哪里f
是表单,t3
来自表单上的自定义指令,该指令检测是否尝试了提交,并且包含用于检查字段有效性的函数。
我想要完成的是改为在弹出窗口中显示验证消息。引导程序的本机弹出窗口或UI Bootstrap的弹出窗口都已加载。如果使用该库更容易做到这一点,我也可以考虑使用AngularStrap。
我现在正努力解决的是弹出窗口的本质,它们会根据用户事件(例如单击,鼠标进入,模糊等)自动显示。我要做的是基于相同的窗口来显示和隐藏弹出窗口上面的ng-
show属性中的功能。这样,当表达式返回false时将其隐藏,而当返回true时将其显示。
我知道bootstrap为此具有.popover(’show’),但是我不应该对dom进行任何介绍,所以我不确定如果如何访问$(element).popover()在自定义表单控制器功能中执行此操作。我想念什么吗?
更新资料
重复表决中提到的解决方案仍然仅在mouseenter上显示弹出窗口。我想强迫它显示,好像在做$('#popover_id').popover('show')
。
事实证明,使用自定义指令装饰ui-
bootstrap工具提示或弹出框并不是很困难。这是用打字稿写的,但是其中的javascript部分应该很明显。这段代码可以修饰工具提示或弹出框:
'use strict';
module App.Directives.TooltipToggle {
export interface DirectiveSettings {
directiveName: string;
directive: any[];
directiveConfig?: any[];
}
export function directiveSettings(tooltipOrPopover = 'tooltip'): DirectiveSettings {
var directiveName = tooltipOrPopover;
// events to handle show & hide of the tooltip or popover
var showEvent = 'show-' + directiveName;
var hideEvent = 'hide-' + directiveName;
// set up custom triggers
var directiveConfig = ['$tooltipProvider', ($tooltipProvider: ng.ui.bootstrap.ITooltipProvider): void => {
var trigger = {};
trigger[showEvent] = hideEvent;
$tooltipProvider.setTriggers(trigger);
}];
var directiveFactory = (): any[] => {
return ['$timeout', ($timeout: ng.ITimeoutService): ng.IDirective => {
var d: ng.IDirective = {
name: directiveName,
restrict: 'A',
link: (scope: ng.IScope, element: JQuery, attr: ng.IAttributes) => {
if (angular.isUndefined(attr[directiveName + 'Toggle'])) return;
// set the trigger to the custom show trigger
attr[directiveName + 'Trigger'] = showEvent;
// redraw the popover when responsive UI moves its source
var redrawPromise: ng.IPromise<void>;
$(window).on('resize', (): void => {
if (redrawPromise) $timeout.cancel(redrawPromise);
redrawPromise = $timeout((): void => {
if (!scope['tt_isOpen']) return;
element.triggerHandler(hideEvent);
element.triggerHandler(showEvent);
}, 100);
});
scope.$watch(attr[directiveName + 'Toggle'], (value: boolean): void => {
if (value && !scope['tt_isOpen']) {
// tooltip provider will call scope.$apply, so need to get out of this digest cycle first
$timeout((): void => {
element.triggerHandler(showEvent);
});
}
else if (!value && scope['tt_isOpen']) {
$timeout((): void => {
element.triggerHandler(hideEvent);
});
}
});
}
};
return d;
}];
};
var directive = directiveFactory();
var directiveSettings: DirectiveSettings = {
directiveName: directiveName,
directive: directive,
directiveConfig: directiveConfig,
};
return directiveSettings;
}
}
通过这段代码,您可以设置工具提示或弹出窗口的程序化隐藏和显示,如下所示:
var tooltipToggle = App.Directives.TooltipToggle.directiveSettings();
var popoverToggle = App.Directives.TooltipToggle.directiveSettings('popover');
var myModule = angular.module('my-mod', ['ui.bootstrap.popover', 'ui.bootstrap.tpls'])
.directive(tooltipToggle.directiveName, tooltipToggle.directive)
.config(tooltipToggle.directiveConfig)
.directive(popoverToggle.directiveName, popoverToggle.directive)
.config(popoverToggle.directiveConfig);
用法:
<span tooltip="This field is required."
tooltip-toggle="formName.fieldName.$error.required"
tooltip-animation="false" tooltip-placement="right"></span>
要么
<span popover="This field is required."
popover-toggle="formName.fieldName.$error.required"
popover-animation="false" popover-placement="right"></span>
因此,我们将重用ui-
bootstrap工具提示或弹出窗口附带的所有其他内容,并且仅实现该-toggle
属性。装饰性指令监视该属性,并触发自定义事件以显示或隐藏,然后由ui-
bootstrap工具提示提供程序处理。
更新:
由于此答案似乎对其他人有所帮助,因此以下是用javascript编写的代码(上述打字稿或多或少都编译为该javascript):
'use strict';
function directiveSettings(tooltipOrPopover) {
if (typeof tooltipOrPopover === "undefined") {
tooltipOrPopover = 'tooltip';
}
var directiveName = tooltipOrPopover;
// events to handle show & hide of the tooltip or popover
var showEvent = 'show-' + directiveName;
var hideEvent = 'hide-' + directiveName;
// set up custom triggers
var directiveConfig = ['$tooltipProvider', function ($tooltipProvider) {
var trigger = {};
trigger[showEvent] = hideEvent;
$tooltipProvider.setTriggers(trigger);
}];
var directiveFactory = function() {
return ['$timeout', function($timeout) {
var d = {
name: directiveName,
restrict: 'A',
link: function(scope, element, attr) {
if (angular.isUndefined(attr[directiveName + 'Toggle']))
return;
// set the trigger to the custom show trigger
attr[directiveName + 'Trigger'] = showEvent;
// redraw the popover when responsive UI moves its source
var redrawPromise;
$(window).on('resize', function() {
if (redrawPromise) $timeout.cancel(redrawPromise);
redrawPromise = $timeout(function() {
if (!scope['tt_isOpen']) return;
element.triggerHandler(hideEvent);
element.triggerHandler(showEvent);
}, 100);
});
scope.$watch(attr[directiveName + 'Toggle'], function(value) {
if (value && !scope['tt_isOpen']) {
// tooltip provider will call scope.$apply, so need to get out of this digest cycle first
$timeout(function() {
element.triggerHandler(showEvent);
});
}
else if (!value && scope['tt_isOpen']) {
$timeout(function() {
element.triggerHandler(hideEvent);
});
}
});
}
};
return d;
}];
};
var directive = directiveFactory();
var directiveSettings = {
directiveName: directiveName,
directive: directive,
directiveConfig: directiveConfig,
};
return directiveSettings;
}
描述 (Description) 可以使用相关的app方法动态创建popover,如下所示 - myApp.popover(popoverHTML, target, removeOnClose) - 此方法接受以下参数 popoverHTML - 它是popoverHTML的HTML字符串。 target - 它是一个HTMLElement or string (with CSS Selector
描述 (Description) 您还可以使用HTML到App方法创建动态弹出窗口。 它使用两个参数 - popupHTML - 它包含Popup内容的字符串元素。 removeOnClose - 它包含布尔值,当您关闭Popup时,它将从DOM中删除。 默认情况下,它包含真值。 例子 (Example) 以下示例演示了在Framework7中使用动态弹出窗口 - <!DOCTYPE html>
我正在尝试创建弹出与Vimeo视频在里面。我的页面上有divideid=“showvideo”。单击要打开弹出窗口的div(带有id=“Opened-Video”的新div)。id=“open-video”的Div有如下所示的Viemo视频的iframe 使用src URL中的?autoplay=1参数将此iframe设置为自动播放。 这是我的JavaScript 这就管用了。 您将注意到html
我有一个通过angular $http.post将数据发布到ASPNET MVC页面的页面(..)当调用结束时,我必须提交一个表单。 基本上我执行以下操作: 当我这样做document.forms["CheckPay"]。提交();我方面有一个重定向到页面,这是我的表单的属性操作,而不是我得到一个弹出的页面,我将重定向。 我已经尝试将函数payTest()排除在“成功”之外,它可以工作,然后我认为
问题内容: 我在JPopupMenu中有一个JComboBox(以及其他组件)。事实证明,每当我打开组合框的弹出窗口(以选择一个项目)时,父级JPopupMenu都会关闭。我一直在尝试找到一种方法来覆盖此功能,但无济于事。 有没有人建议防止关闭父级JPopupMenu?谢谢! 问题答案: 这不可能直接实现,很难覆盖已知的错误,另一方面,Swing不允许同时使用两个lightwieght弹出组件 但
但是我在系统上有另一个会话(相同的项目并且似乎是相同的条件),无论我测试什么,都不可能打开这个工具窗口。我可以调试、设置断点并通过“快速评估”查看值,但评估表达式窗口无法打开。 在这一点上,我不提供更多的项目信息,因为我不认为这会有什么不同。。。 我首先尝试了另一个空项目,我有同样的行为,所以这可能是macos的问题,我不知道。我还尝试在第二个会话中重新安装IDE,但它也会这样做。 在我做了一些不