使用dirtyforms jQuery插件的DropDownList

时间:2013-01-25 14:27:21

标签: forms kendo-ui jquery-dirtyforms

我想使用jQuery插件dirtyForms检查我的表单是否脏。 但看起来DropDownList不是基于标准的选择HTML标记。 似乎它正在使用

  • HTML标记。 为什么选择这个?因为当我只更改DropDownList值时,jquery插件dirtyForms不会将我的表单设置为脏...

  • 2 个答案:

    答案 0 :(得分:0)

    我对kendo-ui或dirtyForms一无所知,所以我会尽力通过查看API来回答这个问题。 kendo-ui DropDownList有一个change event,只要DropDownList中的输入发生变化,它就会被触发。另外dirtyForms有一种方式manually setting the form to dirty。将两者结合在一起我猜想以下内容应该可行。

    $("#dropdownlist").kendoDropDownList({
        change: function(e) {
            $('form').dirtyForms('setDirty');
        }
    });
    

    编辑:由于您似乎希望这会影响所有DropDownList,因此您可以执行以下操作。

    kendo.ui.DropDownList.fn._change = function(e) {
        if(this.element && this.element.form)
            $(this.element.form).dirtyForms('setDirty');
    }
    

    这似乎有点hackish,我不确定我是否会建议这样做。它可能会打破其他事情。

    答案 1 :(得分:0)

    这听起来像是pull request 27中修复的错误,它允许跨浏览器与选择元素兼容。

    或者,可能是您的标记中没有properly ignored all of the 3rd party widgets on the page have anchor elements