如果验证组无效,JQuery Cycle 插件需要在回发时循环到下一张幻灯片

发布于 2024-10-10 04:39:17 字数 581 浏览 9 评论 0原文

我正在使用 JQuery Cycle 插件(具有在单独的站点范围自定义 js 文件中定义的属性)在表单的两个页面(由表分隔)之间循环。每个页面都有自己的针对该页面上的控件的验证组。第一页有一个“下一步”按钮,单击该按钮会手动触发第一个验证组的页面验证。如果失败,则会显示工具提示,供用户更正信息。如果验证成功,则调用下一个循环命令。

$('#request-information').cycle('next');

在第二页上,控件通过提交按钮分组在第二个验证组中。单击提交按钮时,将触发服务器端验证,如果失败,页面将在回发时重新加载。所有这些都有效,除非第二页失败,我希望表单保留在第二页上。因此,如果由于表单的第二页无法验证而重新加载网页,我需要将起始幻灯片设置为表单的第二页,或者如果不可能,至少触发循环下一个命令。

我似乎无法将起始幻灯片设置为表单的第二页,因为这将覆盖在单独的 js 文件中设置的循环函数的其他定义属性。

那么,有谁知道如何根据单击提交按钮时第二个验证组是否失败来前进到回发页面加载的第二张幻灯片?或者我应该使用视图状态或其他东西做一些不同的事情?

抱歉,这是一个冗长的问题。希望它清晰而不令人困惑。 谢谢

I'm using the JQuery Cycle plugin (with attributes defined in a separate site wide custom js file) to cycle between two pages (separated by tables) of a form. Each page has its own validation group for the controls on that page. The first page has a "Next" button that when clicked manually fires page validation for the first validation group. If it fails the tool tips are displayed for the user to correct the information. If validation succeeds, the cycle next command is called.

$('#request-information').cycle('next');

On the second page, the controls are grouped in a second validation group with the submit button. When the submit button is clicked, server side validation is triggered and if it fails the page reloads on postback. All of this works, except if the second page fails I want the form to stay on the second page. So if the web page is reloaded because the second page of the form failed to validate I need to either set the starting slide to the second page of the form or if that's not possible at least trigger the cycle next command.

It doesn't seem like I can just set the startingslide to the second page of the form because that will overwrite the other defined attributes of the cycle function that are set in the separate js file.

So does anyone know how to advance to the second slide on postback page load based on whether the second validation group failed when the submit button was clicked? Or should I be doing something different using viewstate or something?

Sorry this is a long winded question. Hope its clear and not confusing.
Thank you

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

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

发布评论

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

评论(1

夏花。依旧 2024-10-17 04:39:17

如果您知道页面加载时需要转到第二张幻灯片,那么您可以执行以下操作:

var init = { startingSlide: 1 }; // i.e. second slide, the indices are zero-based
$('whatever').cycle($.extend(init, the_name_of_your_global_default_options));

您只需将 init 安排为空对象文字,除非您需要设置startingSlide。如果 .cycle() 位于页面之外的某个位置,那么您可以为页面特定选项和 $.extend() 保留一个变量,其中 .cycle () 被调用。例如,在您的页面中,您可以执行以下操作:

app_name_space.page_cycle_opts = { startingSlide: 1 };

然后在绑定循环内容的 JavaScript 文件中执行以下操作:

app_name_space.page_cycle_opts = app_name_space.page_cycle_opts || { };
$('whatever').cycle($.extend(app_name_space.page_cycle_opts, default_options));

我使用 app_name_space 作为应用程序的任何全局命名空间的占位符已用于避免名称冲突。如果您必须在单个页面上处理多个循环实例,那么您需要通过元素 ID 来索引 page_cycle_opts,例如:

app_name_space.page_cycle_opts['X'] = { startingSlide: 1 };

然后在其他地方进行索引:

$('whatever').each(function() {
    $(this).cycle($.extend(
        app_name_space.page_cycle_opts[this.id] || { },
        default_options
    ));
});

基本思想是考虑全局配置选项作为一组默认值,然后通过明确定义和记录的机制允许特定于页面的覆盖。

对一个冗长问题的冗长回答。希望它清晰而不令人困惑。

If you know that you need to go to the second slide when your page loads then you could do something like this:

var init = { startingSlide: 1 }; // i.e. second slide, the indices are zero-based
$('whatever').cycle($.extend(init, the_name_of_your_global_default_options));

You'd just have to arrange for init to be an empty object literal except when you needed to set startingSlide. If .cycle() is being somewhere outside your page, then you could reserve a variable for page-specific options and $.extend() that where .cycle() is called. For example, in your page, you could do something like this:

app_name_space.page_cycle_opts = { startingSlide: 1 };

and then way off in the JavaScript file that is binding the cycle stuff:

app_name_space.page_cycle_opts = app_name_space.page_cycle_opts || { };
$('whatever').cycle($.extend(app_name_space.page_cycle_opts, default_options));

I'm using app_name_space as a placeholder for whatever global namespace your application is already using to avoid name conflicts. If you had to deal with multiple cycle instances on a single page then you'd want to index page_cycle_opts by element ID, for example:

app_name_space.page_cycle_opts['X'] = { startingSlide: 1 };

and then way off elsewhere:

$('whatever').each(function() {
    $(this).cycle($.extend(
        app_name_space.page_cycle_opts[this.id] || { },
        default_options
    ));
});

The basic idea is to consider the global configuration options as a set of defaults and then allow page-specific overrides through a well defined and documented mechanism.

A long winded answer to a long winded question. Hope its clear and not confusing.

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