[英]how to set input focus on kendo-ui grid input inside bootstrap modal
Before moving my kendo-ui grid inside a bootstrap modal I would click on Add Row and the first of 3 inputs would be selected. 在将我的kendo-ui网格移动到bootstrap模式中之前,我会点击Add Row,然后选择3个输入中的第一个。 I would then tab to the 2nd, then 3rd and then tab to the checkbox button where I would press enter and the row would be added.
然后我会选择第二个,然后是第三个然后选项卡到复选框按钮,我将按下回车键并添加行。 Then the focus would go back to the Add Row button to where I could press enter to start process over again.
然后焦点将返回到“添加行”按钮,我可以按Enter键再次开始处理。 Well now that it is inside a modal I lost everything except for tabbing.
那么现在它在一个模态中我失去了除了标签之外的一切。 I have found solutions that use jquery to apply focus but I already have that inside my grid controller.
我找到了使用jquery来应用焦点的解决方案,但我已经在我的网格控制器中有了它。
Kendo-ui grid controller Kendo-ui网格控制器
$scope.mainGridOptions = {
dataSource: dataSource,
pageable: false,
toolbar: [{ name: "create", text: "Add Product", }],
columns: [
{ field: "product", title: "Product", width: "95px", editor: productEditor },
{
field: "price", title: "Price", width: "95px", format: "{0:c2}", editor: priceEditor
},
{
field: "sqft", title: "Square Feet", width: "95px", editor: sqftEditor
},
{
command: [{ name: 'edit', text: { edit: '', update: '', cancel: '' }, width: '20px' }, { name: 'destroy', text: '' }], title: ' ', width: '80px'
}],
editable: 'inline'
};
function productEditor(container, options) {
$('<input id="product" name="product" data-bind="value:product" data-productvalidation-msg="Put the Product!" />')
.appendTo(container)
.kendoMaskedTextBox({});
$("#product").focus(function () {
var input = $(this);
setTimeout(function () {
input.select();
});
});
};
function priceEditor(container, options) {
$('<input id="price" name="price" data-bind="value:price" data-step="10000" style="" data-productvalidation-msg="Put the Price!"/>')
.appendTo(container)
.kendoNumericTextBox({ format: 'c0', min: 0 });
$("#price").focus(function () {
var input = $(this);
setTimeout(function () {
input.select();
});
});
}
function sqftEditor(container, options) {
$('<input id="sqft" name="sqft" data-bind="value:sqft" data-step="500" style="" data-productvalidation-msg="Put the Sqft!"/>')
.appendTo(container)
.kendoNumericTextBox({ format: '0', min: 0 });
$("#sqft").focus(function () {
var input = $(this);
setTimeout(function () {
input.select();
});
});
};
Modal 语气
<!-- Grid Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<div style="width:100%"><span class="modal-label">My Product Data</span><button style="float:right" class="btn btn-custom waves-effect" data-dismiss="modal"><i class="zmdi zmdi-close"></i></button></div>
</div>
<div class="modal-body">
<div kendo-grid id="grid" options="mainGridOptions"></div>
</div>
</div>
</div>
</div><!--End Grid Modal -->
Function to open modal 打开模态的功能
$scope.openGrid = function () {
$('#myModal').modal('show');
};
On the API Functions for NumericTextBox Kendo-UI control it shows that focus can be obtained by performing the following pseudo-code: 在NumericTextBox Kendo-UI控件的API函数上,它显示可以通过执行以下伪代码获得焦点:
var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
numerictextbox.focus();
So applying this to your code it would look something like this: 所以将它应用到您的代码中它看起来像这样:
var price= $("#price").data("kendoNumericTextBox");
price.focus();
Additionally since your modal popup is more of an application I would suggest switching the accessability attributes from 此外,由于您的模态弹出窗口更像是一个应用程序,我建议切换可访问性属性
role="document"
to role="application"
role="document"
to role="application"
I think the focus is hijacked from the bootstrap modal itself, you can use the shown
event and set the focus accordingly. 我认为焦点是从bootstrap模态本身被劫持,你可以使用
shown
事件并相应地设置焦点。
Ref: 参考:
Bootstrap provides custom events for most plugins' unique actions.
Bootstrap为大多数插件的独特操作提供自定义事件。 Generally, these come in an infinitive and past participle form - where the infinitive (ex. show) is triggered at the start of an event, and its past participle form (ex. shown) is triggered on the completion of an action.
通常,它们以不定式和过去的分词形式出现 - 其中不定式(例如show)在事件开始时触发,并且其过去的分词形式(例如显示)在动作完成时触发。
As of 3.0.0, all Bootstrap events are namespaced.
从3.0.0开始,所有Bootstrap事件都是命名空间。
All infinitive events provide preventDefault functionality.
所有不定式事件都提供preventDefault功能。 This provides the ability to stop the execution of an action before it starts.
这提供了在动作开始之前停止执行的能力。
Code: 码:
$('#myModal').on('shown.bs.modal', function () {
//your current focus set
});
Try this… in show modal window 试试这个......在show modal窗口中
this.$workModal.on('show.bs.modal', (e) => {
$('#workId_input').data('kendoNumericTextBox').focus();
});
on UI.... You need to have ID on input… 在UI ....你需要输入ID ...
<input id='workId_input', data-bind="kendoNumericTextBox ......">
Try this.. you just need to turn off Event Listener attached by Bootstrap. 试试这个..你只需要关闭Bootstrap附带的事件监听器。
$('#myModal').on('shown.bs.modal', function() {
$(document).off('focusin.modal');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.