防止单击添加按钮时打开表单

发布于 2024-09-01 08:22:13 字数 580 浏览 5 评论 0原文

你们知道当我单击添加按钮时如何防止打开表单吗?

也许使用 beforeShowForm ?

function(formid)
{
    if(jQuery('#gridap').getGridParam('selrow'))
    {

        idgridap=jQuery('#gridap').getGridParam('selrow');
        jQuery('#FK_numerocontrato_ap',formid).val(idgridap).attr('readonly','readonly');

    }
    else 
    {
         // I want to prevent the openning of the add form here and maybe show an alert using the "alertcap"

    }
}
CHECAROW;

$grid->setNavEvent('add','beforeShowForm',$checarowid);

BTW,有没有办法调用jqgrid的alertmod并向其添加自定义消息?

谢了!

Did you guys know how to prevent the open of a Form when I click on a add button?

Maybe using beforeShowForm?

function(formid)
{
    if(jQuery('#gridap').getGridParam('selrow'))
    {

        idgridap=jQuery('#gridap').getGridParam('selrow');
        jQuery('#FK_numerocontrato_ap',formid).val(idgridap).attr('readonly','readonly');

    }
    else 
    {
         // I want to prevent the openning of the add form here and maybe show an alert using the "alertcap"

    }
}
CHECAROW;

$grid->setNavEvent('add','beforeShowForm',$checarowid);

BTW, there's a way to call the alertmod of jqgrid and add a custom message to it?

tks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦上情书 2024-09-08 08:22:13

我不明白为什么您不直接从导航栏中删除“添加”按钮。要创建导航栏,您需要显式调用 jqGrid 的 navGrid 方法

jQuery("#grid_id").navGrid('#gridpager'); 

,或者

jQuery("#grid_id").jqGrid('navGrid', '#gridpager');

navGrid 有其他参数(请参阅 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator)。因此,如果您使用,

jQuery("#grid_id").navGrid('#gridpager', {add: false}); 

将不会有“添加”按钮。

如果您确实需要“添加”按钮,请更清楚地解释您的情况。顺便说一下 http://www.trirand 中描述的方式。 com/jqgridwiki/doku.php?id=wiki:custom_buttons 您可以添加一个自定义按钮,并从您这边完全控制。如果您放置了图标的名称,您可以在页面 http://jqueryui.com/themeroller/ 上找到将光标悬停在页面底部“框架图标”区域的图标上。自定义按钮可以具有与“添加”按钮相同的图标。它能解决您的问题吗?

更新:在您发表评论后,我现在明白您的问题了。我可以建议使用 navGridaddfunc 选项(请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator&s[]=navgrid)。因此,代码可能如下所示:

var grid = jQuery("#grid_id").navGrid('#gridpager', {addfunc: function() {
    var sel_id = grid.getGridParam('selrow');
    if (sel_id) {
        grid.editGridRow("new", pAddOption);
    } else {
        viewModal("#alertmod", { gbox: "#gbox_" + grid_id, jqm: true });
        jQuery("#jqg_alrt").focus();
    }
}});

在此示例中,仅当选择一行时才允许单击“添加”按钮。您将看到一个消息框,其中包含类似“请选择行”的文本(该文本在grid.locale-en.js中定义$.jgrid.nav.alerttext > 或您使用的其他本​​地化文件)。您可以将此代码片段放置在主网格中。

拒绝“添加”操作的代码可以更简单,我只是在这里复制了使用 jqGrid 本身的代码片段。您可以改为显示自定义错误消息。

I don't understand why you not just remove "Add" button from the navigation bar. To create a navigation bar you explicitly call navGrid method of jqGrid

jQuery("#grid_id").navGrid('#gridpager'); 

or

jQuery("#grid_id").jqGrid('navGrid', '#gridpager');

but navGrid has additional parameters (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator). So if you use

jQuery("#grid_id").navGrid('#gridpager', {add: false}); 

you will be have no "Add" button.

If you do need have "Add" button, please explain your situation more clear. By the way with the way described in http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons you can add an custom button with full control from your side. The name of icon you can find on the page http://jqueryui.com/themeroller/ if you place a cursor over the icon on the "Framework Icons" area on the bottom of the page. The custom button can have the same icon as the "Add" button has. Can it solve your problem?

UPDATED: Now after your comment I understand your problem. I can suggest to use addfunc option of navGrid (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator&s[]=navgrid). So the code could looks like following:

var grid = jQuery("#grid_id").navGrid('#gridpager', {addfunc: function() {
    var sel_id = grid.getGridParam('selrow');
    if (sel_id) {
        grid.editGridRow("new", pAddOption);
    } else {
        viewModal("#alertmod", { gbox: "#gbox_" + grid_id, jqm: true });
        jQuery("#jqg_alrt").focus();
    }
}});

In this example will be allowed to click "Add" button only if a row is selected. You will see a message box with the text like "Please, select row" (the text which defines $.jgrid.nav.alerttext inside of grid.locale-en.js or other localization file which you use). You can place this code fragment in your master grid.

The code in case of denying of "Add" operation can be easier, I just copied here a code fragment which use jqGrid itself. You can display your custom error message instead.

沉默的熊 2024-09-08 08:22:13

酷,谢谢奥列格!
顺便说一句,我提出了另一个(但不是很漂亮)的解决方案:

** 这是一个 aftershowform 操作。
如果我们在主网格(#gridap)上没有选定的行,我们可以使用 jqmHide() 隐藏表单模式。
然后,我使用您的解决方案来显示alertcap。


$closeform = <<< CLOSEF
function(formid)
{
    if(!jQuery('#gridap').getGridParam('selrow'))
    {
        $('#editmodgridbal').jqmHide();
        viewModal('#alertmod', { gbox: '#gbox_', jqm: true });
    }
}
CLOSEF;

$grid->setNavEvent('add','afterShowForm',$closeform);

Cool, tks Oleg!!!
BTW, I came with another(but not beautifull) solution:

** This is a aftershowform action.
If we do not have a selected row on the main grid(#gridap), we hide the form modal with jqmHide().
Then, I use your solution to show the alertcap.


$closeform = <<< CLOSEF
function(formid)
{
    if(!jQuery('#gridap').getGridParam('selrow'))
    {
        $('#editmodgridbal').jqmHide();
        viewModal('#alertmod', { gbox: '#gbox_', jqm: true });
    }
}
CLOSEF;

$grid->setNavEvent('add','afterShowForm',$closeform);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文