2012-02-13 19 views
0

Drupal 6のサイトをDrupal 7に移行する途中です。その結果、コードに関するいくつかの問題に直面しています。 jqueryなどでレースされたjavascriptの呼び出しは、Drupal 7では私が読んだものとは異なります。 This is the image of the page i had in Drupal 6. ドロップダウンボックスが変更されると、その上のテーブルには ステータスに属するプロジェクトが表示されます。これはDrupal 6でうまくいきます。 しかし、Drupal 7で表示されますthis javascript error.Drupal 6で適切に実行されていたDrupal 7でJavascript関数が呼び出されない

これは私のPHPファイルのドロップダウンのフォーム要素です。

<? php 
$form['status_list'] = array(
'#type' => 'select', 
'#title' => t('Freeway Project Statuses'), 
'#options' => array(
    0 => t('-Select Status-'), 
    1 => t('Draft'), 
    2 => t('NotSpecified'), 
    3 => t('Quote'), 
    4 => t('Forecasted'), 
    5 => t('InEvaluation'), 
    6 => t('Cancelled'), 
    7 => t('Booked'), 
    8 => t('InProduction'), 
    9 => t('Completed'), 
    10 => t('Closed'), 
), 
'#default_value' => array('0' => 'Select Status'), 
'#weight' => 0, 
); 

そして、これは私がこれらのタグは、Drupalの6で必要とされていなかった

 (function$){ 
    $(document).ready(function() { 
    $("#edit-status-list").change(function() { 
    var selectedStatus = $(this).find(":selected").text(); 
    var charExists = ((window.location.href).indexOf('?') >= 0) ? true : false; 

    if(charExists){ 
    var split = (window.location.href).split('?'); 
    var loc = split[0]; 

     loc = loc+"?status="+selectedStatus; 
    self.location.href= loc; 

    } 

    else{ 
    var locf = window.location.href+"?status="+selectedStatus; 
    self.location.href= locf; 

    } 

    }); 

    $("#create-freeway-project").submit(function() { 
     $(":submit", this).attr("disabled", "disabled"); 

    }); 

    $(".common_link_class").click(function() { 
      //alert("Hello"); 

     var count = ($(this).data("clicks") || 0) + 1; 
     $(this).data("clicks", count); 


     if ($(this).data("clicks") >= 1) { 

     } 


     if ($(this).data("clicks") >= 2) { 

     return false; 
     } 
    }); 


     $("#edit-analysis-code-one").change(function() { 
     // Get the configs and split them. 
     var cfgs = _get_configs("edit-custRef"); 
     var split_cfgs = cfgs.split('/'); 

     // Create some new configs and put it back into the configs textfield. 
     //var new_cfgs = $(this).val() +"/"+ cfgs[1]; 
     var new_cfgs = $("#edit-analysis-code-one option:selected").text() +"/"+ cfgs[1]; 

     $("#edit-custRef").val(new_cfgs); 
     }); 

     $("#edit-analysis-code-two").change(function() { 
     // Get the configs and split them. 
     var cfgs = _get_configs("edit-custRef"); 
     var split_cfgs = cfgs.split('/'); 

     // Create some new configs and put it back into the configs textfield. 
     //var new_cfgs = cfgs[0] +"/"+ $(this).val(); 
     var new_cfgs = cfgs[0] +"/"+ $("#edit-analysis-code-two option:selected").text() 
     $("#edit-custRef").val(new_cfgs); 
    }); 


    }); 

})(jQuery); 


(function$){ 
function _get_configs(id) { 

    return $("#"+ id).val(); 

} 
})(jQuery); 

#edit_status_listがあるDrupalの7

(function$){ .. })(jQuery); . 

のための追加のタグでそれを変更したJavaScriptの です私たちの興味のドロップダウン。どのような追加の変更には、それは

(function($) { 

ない

(function$ { 

何であるべきDrupalの7

答えて

0

に呼び出す適切javasciptのために行われる必要があるよう

はあなたの提案を持っていますか構文エラーです。最初の引数は、その最初の引数がシンボル$の本体コードで利用できるように関数をインスタンス化します。機能は、本体の後に呼び出されます。

// ... 
})(jQuery); 

とグローバル「jQueryの」オブジェクトが引数として渡されます。この設定は、 "$"の別の外部バインディングを心配することなく、共通の "$"記号を使用して、正しいフレームワーク(つまり、jQuery)へのコードアクセスを保証します。

+0

ありがとうPointyこれは、JavaScriptの投げエラーのエラーが解決されました。しかし、Jqueryメソッドは反映されていません。私は同じことについて新しい疑問を提起します。 –

+0

こんにちは、私はこの関連する質問のあなたの意見を持っていたいと思いますhttp://stackoverflow.com/questions/9264892/drupal-7-table-theme-unable-to-display-values-seen-in-firebug –

関連する問題