BlackMario
BlackMario

Reputation: 55

Access to Tapestry JavaScript object in Tapestry 5.3.6 (used to be $T, now deprecated)

I'm working with Tapestry 5.3.6. I'm migrating an app which has a component, this component has a JavaScript part and in this JS part I need to access a Tapestry Object with the variable $T. But this variable is deprecated now, how can I do that in an other way? I need to access the fieldEventManager of my form's input to be precise.

Currently my code looks like this:

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;
            }
        }
    });

Upvotes: 0

Views: 570

Answers (1)

Steve Eynon
Steve Eynon

Reputation: 5139

I don't think there is a direct replacement for $T, but it looks like the getFieldEventManager() method has been directly added to form inputs via Prototype.

Adapting your function:

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;
            }
        }
    });

For more info, tapestry.js for T5.3.6 at line 830 defines the following:

Element.addMethods([ 'INPUT', 'SELECT', 'TEXTAREA' ], {
    getFieldEventManager: function (field) {
    ...
    }
}

Upvotes: 1

Related Questions