2

ValidationTextBoxから継承するカスタムDojoValidationIdBoxウィジェットを作成しようとしています。私のカスタムウィジェットは、バックエンドサーバーで非同期の重複IDチェックを追加します。

dijit.form.ValidationTextBoxをサブクラス化し、isValid()とvalidate()の2つのメソッドを変更しました。ただし、検証を完全に機能させることができません。ウィジェットは、必要な入力が欠落しているなどの問題をキャッチして強調表示します。IDが重複している場合でもキャッチします(ツールチップが表示されます)が、期待どおりにフィールドを強調表示できません。

以下の簡略化されたコードスニペットを使用して、問題を切り分けようとしました。これは主に、いくつかのマイナーな変更を加えた元のDojoコードです。私の一般的な戦略は、ウィジェットを通常のValidationTextBoxとして検証してから、重複するIDをテストすることです。isValid()を変更して、プレーン検証と一意性チェックによる検証の2つのモードを設定しました。現在、一意性テストは意図的に常に失敗します。

同様の方法で、validate()を変更して通常の処理を実行し、通常の検証は成功したが一意性テストによる検証が失敗した場合は、追加の処理を実行します。ValidationTextBoxが状態にあるときと同じロジックをミラーリングしようとしましたerrorが、同じ効果はミラーリングされません。「ID not available」ツールチップは表示されますが、感嘆符付きの赤いアウトラインは表示されません。

ValidationTextBoxのコードを調べましたが、その特別なスタイルがどのようにトリガーされるのかわかりません...誰かがValidationTextAreaの仕組みを説明できますか?具体的には、、、およびがどのようthis._maskValidSubsetErrorに使用されているのかよくわかりません。aria-invalidthis.state

(また、ツールチップを表示したいが、赤いスタイルは表示したくない場合があります。AJAX重複IDチェック要求が処理されているときに表示したい場合があります。)

// If ValidationTextBoxValidates
isValid: function(isFocused, requireUnique) {
    if (typeof requireUnique === 'undefined') requireUnique = false;

    var isValid = this.inherited(arguments);
    var isUnique = false;

    return (requireUnique ? (isValid && isUnique) : isValid);
},

validate: function(/*Boolean*/ isFocused){
    // summary:
    //        Called by oninit, onblur, and onkeypress.
    // description:
    //        Show missing or invalid messages if appropriate, and highlight textbox field.
    // tags:
    //        protected
    var message = "";
    var isValid = this.disabled || this.isValid(isFocused);
    if(isValid){ this._maskValidSubsetError = true; }
    var isEmpty = this._isEmpty(this.textbox.value);
    var isValidSubset = !isValid && isFocused && this._isValidSubset();
    this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
    this.focusNode.setAttribute("aria-invalid", isValid ? "false" : "true");

    if(this.state == "Error"){
        this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
        message = this.getErrorMessage(isFocused);
    }else if(this.state == "Incomplete"){
        message = this.getPromptMessage(isFocused); // show the prompt whenever the value is not yet complete
        this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; // no Incomplete warnings while focused
    }else if(isEmpty){
        message = this.getPromptMessage(isFocused); // show the prompt whenever there's no error and no text
    }

    /// Begin custom widget code
    if (isValid && !this.isValid(isFocused, true) ) {
        isValid = false;

        var isValidSubset = !isValid && isFocused && this._isValidSubset();

        this._maskValidSubsetError = isFocused && isValidSubset; // we want the error to show up after a blur and refocus
        message = 'ID not available';

        this.focusNode.setAttribute("aria-invalid", isValid ? "false" : "true");
    }
    /// End custom widget code

    this.set("message", message);
    return isValid;
},
4

1 に答える 1

3

インラインの雲の中に隠された明白なものが欠けている可能性があります&&|| ;))))))

ぼかし/キープレスメカニズムのポイントは、ツールチップが現在表示されているボックスにのみ表示されるため、_maskValid

試しましたthis.set("state", this.isUnique() ? "" : "Error");か?

ウィジェットはステートフルであり、.setは単にトリックを実行したり、イベントを発生させたり、トピックを公開したりする可能性があります

于 2012-04-29T16:44:09.253 に答える