验证一个复选框在下一页/上一页之前从组中签出 [英] Validate one checkbox is checked out of group before next/previous page

查看:66
本文介绍了验证一个复选框在下一页/上一页之前从组中签出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证其中一个复选框已经过检查,然后再转到下一页/上一页,但看起来我的支票没有被点击。这个网站最初由其他人完成,我不经常在网站上工作。



我有一套填写的表格,这是一部分我的第二个标签:



RegisterStep2.cshtml中的第一个复选框如下:



I'm trying to validate one of the checkboxes is checked before going to the next/previous page, but it doesn't look like my check is hit. This website was originally done by someone else and I don't work on websites very often.

I have a set of forms that are filled out, and this is part of my second tab:

The first checkbox is as follows in RegistrationStep2.cshtml:

..
<tbody>
            <tr>

                <td>
                    <div class="col-md-12">
                        <div class="col-md-16">
                            <div>

                                @Html.EditorFor(model => model.PrivilegesS, new { htmlAttributes = new { @class = "RoleChk2" } })
                                <label for="PrivilegesS">(S)</label>

                            </div>
                        </div>

                    </div>
                </td>
       </tr>
  </tbody>
</table> 





表格是下一个/上一个按钮后:





After the table are the Next/Previous buttons:

<footer class="col-xs-12 form-group text-right">

        @(Html.Kendo().Button()
                          .Name("Previous1")
                          .Content("Previous")
                          .Events(ev => ev.Click("onPreviousClick")))

        @(Html.Kendo().Button()
                          .Name("Next4")
                          .Content("Next")
                          .HtmlAttributes(new { @class = "k-primary" })
                          .Events(ev => ev.Click("onNextClick")))
</footer>





我尝试添加一个脚本来查看是否在模型中设置了任何复选框,但我从未看到过警报它让我进入下一个屏幕,这是不好的:





I tried adding a script to see if any of the checkboxes are set in the model, but I never see an alert and it lets me go to the next screen, which is not good:

<script>
    @*This is my script for my checkboxes..the following does not get hit when run code*@
    $('input.Previous1'.on('click',
    function () {
        if (!model.PrivilegesS && !model.PrivilegesAJ && !model.PrivilegesT && !model.PrivilegesH && !model.PrivilegesE && !model.PrivilegesM && !model.PrivilegesFF) {
            alert('At least one facility privilege must be selected');
            return false;
        }
    }));

    $('input.Next4'.on('click',
    function () {
        if (!model.PrivilegesS && !model.PrivilegesAJ && !model.PrivilegesT && !model.PrivilegesH && !model.PrivilegesE && !model.PrivilegesM && !model.PrivilegesFF)  {
            alert('At least one Facility privilege must be selected');
            return false;
        }
    }));
</script>





我有ApplicantCapturedData.cs:



..





I have ApplicantCapturedData.cs:

..

//[Required(ErrorMessage = "Input is required.")]
        public bool PrivilegesS { get; set; }

        public bool PrivilegesH { get; set; }

        public bool PrivilegesFF { get; set; }



..这里有复选框变量列表..





我也尝试将其附加到按钮点击中的事件,如 https://demos.telerik.com/aspnet-mvc/button/events ,但它已经有一个事件按钮点击进入下一个/上一个。



****更新****

*我的脚本需要在下一个时运行/单击上一个按钮,这不是更改事件。如果未选中任何复选框,则不会触发更改事件来运行脚本。有一堆Privilege复选框。至少需要检查一个,但是可以检查所有这些(大约有10个复选框,而不是所有复选框)。我需要验证在单击下一个/上一个按钮时是否检查了至少一个。我该怎么做?



*我正在删除不适用于我的复选框的更改脚本,因为如果没有选中复选框,则没有更改事件。我刚离开他们,因为它在代码附近,我想也许有人会有一个类似于我没想过的建议。



*径向按钮在这里不起作用,因为可能选择了多个权限。这不是是/否/也许是事情。这些都是建筑物,它们可以同时出现在所有建筑物中。



我尝试过的事情:



显示的脚本验证但它没有被点击,并且还查看了按钮点击事件,但它已经有一个按钮点击事件。



我还添加了RoleChk2类,但是如果没有选中复选框,则没有点击事件需要注意它被检查。



我考虑添加一个变量来设置是否有任何东西被检查但是我对MVC并不熟悉所以我不确定把它放在哪里。另外,我不确定在下一个/上一个时间点确定是否设置。



我试过只需要一个复选框而不是像整个组一样使用RoleChk2,并且在我的ApplicantCapturedData.cs中是必需的,但是当我添加(un)注释的[ApplicantCapturedData.cs中的必需部分]时,从未得到必需的消息。这与其他表格空白/字符串一起填写,我没有显示。




..has the list of checkbox variables here..


I also tried attaching it to an event in the button click like https://demos.telerik.com/aspnet-mvc/button/events, but it already has an event on button click to next/previous.

****Updates****
* My script needs to run when the next/previous button is clicked, which is not a change event. If no checkboxes are checked, it's not going to trigger a change event to run the script. There are a bunch of Privilege checkboxes. At least one needs to be checked, but all of them (there's about 10 checkboxes, not all are shown) could be checked. I need to verify at least one is checked when the next/previous button is clicked. How do I do this?

* I'm removing the change scripts that aren't for my checkboxes, because if no checkboxes are checked, there is no change event. I just left them in because it was nearby in the code, and I thought maybe someone would have a suggestion that was similar that I hadn't thought of.

* Radial buttons wouldn't work here because there could be more than one Privilege selected. It's not a yes/no/maybe thing. These are buildings, and they could be in all of them at one point.

What I have tried:

The script shown to validate but it doesn't get hit, and also looked into button click event, but it already has a button click event.

I also added RoleChk2 class, but if no checkboxes are checked there's no click event to watch for that it gets checked.

I considered adding a variable to set if anything gets checked but I'm not that familiar with MVC so I'm not sure where to put it. Plus I'm not sure where to check if it's set if they hit next/previous.

I tried making just one checkbox required instead of the whole group like it should be with RoleChk2, and Required in my ApplicantCapturedData.cs, but never got a Required message when I added the (un)commented [Required part in ApplicantCapturedData.cs. This had worked with other form blank/strings to fill that I don't show.

@Html.EditorFor(model => model.PrivilegesS, new { htmlAttributes = new { @class = "RoleChk2", required="required" } })

推荐答案

(' input.Previous1'.on('click',
function(){
if(!model.PrivilegesS&&!model.PrivilegesAJ&&!model.PrivilegesT&& ;! model.PrivilegesH&&!model.PrivilegesE&!model.PrivilegesM&&!model.PrivilegesFF){
alert('必须选择至少一个设施权限');
返回false;
}
}));
('input.Previous1'.on('click', function () { if (!model.PrivilegesS && !model.PrivilegesAJ && !model.PrivilegesT && !model.PrivilegesH && !model.PrivilegesE && !model.PrivilegesM && !model.PrivilegesFF) { alert('At least one facility privilege must be selected'); return false; } }));


('input.Next4'.on('click',
function(){
if(!model.PrivilegesS&&!model.PrivilegesAJ&!model.PrivilegesT&!model.PrivilegesH&&!model.PrivilegesE&&!model.PrivilegesM& ;&!model.P rivilegesFF){
alert('必须至少选择一个Facility特权');
返回false;
}
}));
< / script>
('input.Next4'.on('click', function () { if (!model.PrivilegesS && !model.PrivilegesAJ && !model.PrivilegesT && !model.PrivilegesH && !model.PrivilegesE && !model.PrivilegesM && !model.PrivilegesFF) { alert('At least one Facility privilege must be selected'); return false; } })); </script>





我有ApplicantCapturedData.cs:



..





I have ApplicantCapturedData.cs:

..

//[Required(ErrorMessage = "Input is required.")]
        public bool PrivilegesS { get; set; }

        public bool PrivilegesH { get; set; }

        public bool PrivilegesFF { get; set; }



..这里有复选框变量列表..





我也尝试将其附加到按钮点击中的事件,如 https://demos.telerik.com/aspnet-mvc/button/events ,但它已经有一个事件按钮点击进入下一个/上一个。



****更新****

*我的脚本需要在下一个时运行/单击上一个按钮,这不是更改事件。如果未选中任何复选框,则不会触发更改事件来运行脚本。有一堆Privilege复选框。至少需要检查一个,但是可以检查所有这些(大约有10个复选框,而不是所有复选框)。我需要验证在单击下一个/上一个按钮时是否检查了至少一个。我该怎么做?



*我正在删除不适用于我的复选框的更改脚本,因为如果没有选中复选框,则没有更改事件。我刚离开他们,因为它在代码附近,我想也许有人会有一个类似于我没想过的建议。



*径向按钮在这里不起作用,因为可能选择了多个权限。这不是是/否/也许是事情。这些都是建筑物,它们可以同时出现在所有建筑物中。



我尝试过的事情:



显示的脚本验证但它没有被点击,并且还查看了按钮点击事件,但它已经有一个按钮点击事件。



我还添加了RoleChk2类,但是如果没有选中复选框,则没有点击事件需要注意它被检查。



我考虑添加一个变量来设置是否有任何东西被检查但是我对MVC并不熟悉所以我不确定把它放在哪里。另外,我不确定在下一个/上一个时间点确定是否设置。



我试过只需要一个复选框而不是像整个组一样使用RoleChk2,并且在我的ApplicantCapturedData.cs中是必需的,但是当我添加(un)注释的[ApplicantCapturedData.cs中的必需部分]时,从未得到必需的消息。这与其他表格空白/字符串一起填写,我没有显示。




..has the list of checkbox variables here..


I also tried attaching it to an event in the button click like https://demos.telerik.com/aspnet-mvc/button/events, but it already has an event on button click to next/previous.

****Updates****
* My script needs to run when the next/previous button is clicked, which is not a change event. If no checkboxes are checked, it's not going to trigger a change event to run the script. There are a bunch of Privilege checkboxes. At least one needs to be checked, but all of them (there's about 10 checkboxes, not all are shown) could be checked. I need to verify at least one is checked when the next/previous button is clicked. How do I do this?

* I'm removing the change scripts that aren't for my checkboxes, because if no checkboxes are checked, there is no change event. I just left them in because it was nearby in the code, and I thought maybe someone would have a suggestion that was similar that I hadn't thought of.

* Radial buttons wouldn't work here because there could be more than one Privilege selected. It's not a yes/no/maybe thing. These are buildings, and they could be in all of them at one point.

What I have tried:

The script shown to validate but it doesn't get hit, and also looked into button click event, but it already has a button click event.

I also added RoleChk2 class, but if no checkboxes are checked there's no click event to watch for that it gets checked.

I considered adding a variable to set if anything gets checked but I'm not that familiar with MVC so I'm not sure where to put it. Plus I'm not sure where to check if it's set if they hit next/previous.

I tried making just one checkbox required instead of the whole group like it should be with RoleChk2, and Required in my ApplicantCapturedData.cs, but never got a Required message when I added the (un)commented [Required part in ApplicantCapturedData.cs. This had worked with other form blank/strings to fill that I don't show.

@Html.EditorFor(model => model.PrivilegesS, new { htmlAttributes = new { @class = "RoleChk2", required="required" } })


其他代码正在联系更改;你正在联系点击。



根据你的描述,我不明白为什么。
The other code is hooking up "change"; you're hooking up "click".

Based on your description, I don't see why.


这篇关于验证一个复选框在下一页/上一页之前从组中签出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆