-1

我有一个 jQuery UI 对话框,我试图在对话框中按下按钮时验证输入。

但是,当我单击“添加”按钮并告诉我时它失败了TypeError: t.validation is undefined。据我所知,它是定义的(在init函数中)。

我怀疑我设置不正确,但我看不到在哪里寻找。有人可以告诉我如何解决这个错误吗?

$(document).ready(function(){
    optionsDialogFuncs.init();
});

optionsDialogFuncs = {

    /**
     * Constructor
     */
    init : function(){

        var t = this;   // This object

        $('#add_option').on('click', function(){

            /** Create an object to hold the result of validation checks and the final result */
            t.validtaion = {};
            t.add_option();

        });

    }, // init

    /** Add a single option to the list of predefined options */
    add_option : function(){

        var t = this;   // This object
            tip = $('.validation-tip', '#add-remove-options-form');

        t.validate_add_option();

        /** Check to see if the option was valid */
        if(t.validation.valid !== true){

            /** Output a validation tip to help the user */
            if(t.validation.exists === false){
                tip.text('Please enter an option.');
            } else if(t.validation.exists === false){
                tip.text('This option already exists.');
            } else{
                tip.text('An unknow validation error occured. Please try again.');
            }

        } else{
            // Append input to list of options
            // Update the 'poll_options' textarea
            // Update the dialog display
        }

    }, // add_option

    validate_add_option : function(){

        var t = this,                                   // This object
            new_option = $('#new_option').val(),        // The new option that the user wishes to add
            options_text = $('#poll_options').text(),   // The text form the predefined options textarea, i.e. any existing options
            options = options_text.split("\n");         // The predefiend options as an array

        /** Check to see if this option already exists */
        t.validation.empty = (new_option === '') ? true : false;

        /** Check to see if this option already exists */
        t.validation.exists = $.inArray(new_option, options);

        /** Ensure the option passed all validity checks */
        t.validation.valid = (t.validation.empty === false && t.validation.exists === -1) ? true : false;

    } // validate_add_option

};
4

1 回答 1

4

你拼错了变量。

// this 
t.validtaion = {};
// should be 
t.validation = {}; 
于 2013-10-11T15:37:11.280 回答