1

フォーム編集を使用しています。ドロップダウンボックスからの選択に基づいて、追加フォームと編集フォームの特定のフィールドを無効にしたいのですが。これをトリガーするために使用するのに最適なイベントはどれですか?dataEventsを使用しようとしました:

{    name:'type_cd', 
     edittype:'select', 
     editoptions:{
        dataUrl:'functions.php',
            dataEvents:[{
                type:'change',
                fn: function(e){
                    $(this).setColProp('cntrct_id',{
                         editoptions:{editable:false}
                    });
            } 
       }]                        
    } 
},

これはフォームフィールドに目に見える影響はありませんが、フォームフィールドに入力するとアラートメッセージを受け取ることができるため、フォームフィールドに到達していることはわかっています。

編集

フォームを送信すると、次にフォームを開いたときに、editable:falseに設定された列が表示されません。これは正しい方向への一歩ですが、すぐに編集できないようにしたいと思います。本当に、表示したいのですが、無効になっています(つまり、disabled:true)

4

2 に答える 2

4

まず、dataEvents編集要素の要素にコールバックを登録できます。コールバックの内部は、thisバインドされる DOM 要素に初期化されます。したがって、ハンドラー$(this)内では、グリッドではなく要素のラッパーになります。の使い方が間違っています。change<select>$(this).setColProp

追加/編集フォームの一部の入力フィールドを無効にするには、すべての入力要素がの対応する列のプロパティidの値のように同じになるという事実を利用できます。したがって、入力を無効にする必要がある場合は、要素のプロパティを次のように設定できますnamecolModelcntrct_iddisabledtrueid="cntrct_id"

{
     name: 'type_cd', 
     edittype: 'select', 
     editoptions: {
        dataUrl: 'functions.php',
        dataEvents: [{
            type: 'change',
            fn: function (e) {
                // disable input/select field for column 'cntrct_id'
                // in the edit form
                $("#cntrct_id").prop("disabled", true);
            } 
       }]                        
    } 
}

editoptionsが既存の編集モード (フォーム編集、インライン編集、セル編集) に使用されることを理解することが重要です。すべての編集モードをサポートするコードを書きたい場合は、dataEvents編集モードを検出し、編集フィールドの他の ID を少し使用する必要があります。コード(テストされていません)は次のようになります

{
     name: 'type_cd', 
     edittype: 'select', 
     editoptions: {
        dataUrl: 'functions.php',
        dataEvents: [{
            type: 'change',
            fn: function (e) {
                var $this = $(e.target), $td, rowid;
                // disable input/select field for column 'cntrct_id'
                if ($this.hasClass("FormElement")) {
                    // form editing
                    $("#cntrct_id").prop("disabled", true);
                } else {
                    $td = $this.closest("td");
                    if ($td.hasClass("edit-cell") {
                        // cell editing
                        // we don't need to disable $("#cntrct_id")
                        // because ONLY ONE CELL are edited in cell editing mode
                    } else {
                        // inline editing
                        rowid = $td.closest("tr.jqgrow").attr("id");
                        if (rowid) {
                            $("#" + $.jgrid.jqID(rowid) + "_cntrct_id")
                                .prop("disabled", true);
                        }
                    }
                }
            } 
       }]                        
    } 
}

最後の発言。propメソッドをサポートしていない古いバージョンの jQuery (jQuery 1.6 より前) をまだ使用している場合は、代わりにattrを使用する必要があります。

于 2013-02-19T18:38:19.100 に答える
-1

@Oleg:これは機能しています(アラートメッセージを取得できます)が、フィールドを無効にしていません。フォーム フィールドに特別な値が必要ですか?

于 2013-11-13T18:05:53.140 に答える