0

我正在使用 Tapestry 5.3.6。我正在迁移一个有一个组件的应用程序,这个组件有一个 JavaScript 部分,在这个 JS 部分中,我需要使用变量访问 Tapestry 对象$T。但是这个变量现在已被弃用,我该如何以其他方式做到这一点?fieldEventManager我需要准确地访问我的表单输入。

目前我的代码如下所示:

handleSubmit : function(domevent) {
    var t = $T(this.form);
    t.validationError = false;
    var firstErrorField = null;

    // Locate elements that have an event manager (and therefore, validations)
    // and let those validations execute, which may result in calls to recordError().
    this.form.getElements().each(function(element) {
        var fem = $T(element).fieldEventManager;
        if (fem != undefined) {
            // Ask the FEM to validate input for the field, which fires
            // a number of events.
            var error = fem.validateInput();
            if (error && ! firstErrorField) {
                firstErrorField = element;
            }
        }
    });
4

1 回答 1

1

我认为没有直接替代$T,但看起来该getFieldEventManager()方法已通过 Prototype 直接添加到表单输入中。

调整你的功能:

handleSubmit : function(domevent) {
    var t = $(this.form);
    t.validationError = false;
    var firstErrorField = null;

    // Locate elements that have an event manager (and therefore, validations)
    // and let those validations execute, which may result in calls to recordError().
    t.select("input").each(function(element) {
        var fem = element.fieldEventManager;
        if (fem != undefined) {
            // Ask the FEM to validate input for the field, which fires
            // a number of events.
            var error = fem.validateInput();
            if (error && ! firstErrorField) {
                firstErrorField = element;
            }
        }
    });

有关更多信息,第 830 行的tapestry.jsfor定义了以下内容:T5.3.6

Element.addMethods([ 'INPUT', 'SELECT', 'TEXTAREA' ], {
    getFieldEventManager: function (field) {
    ...
    }
}
于 2013-05-02T11:15:37.320 回答