2012-02-08 83 views

回答

0

我前幾天遇到了同樣的問題。當我設置文本字段屬性onblur和onfocus時,它不起作用。確切地說,它正在工作,但我看不到它,因爲它被profile2模塊的形式改寫。

我想你的形式改變PROFILE2模塊形式之前API負載改變API。所以被覆蓋。我通過在另一個命名空間中創建一個自定義表單來解決我的問題。

function yourCustomModuleName_form_profile2_edit_testing_candidate_form_alter(&$form, &$form_state) { 

    $form['profile_testing_candidate']["field_candidate_name"] = array(
     "#title" => "Candidate Name", 
     "#type" => "textfield", 
     "#required" => TRUE, 
     "#description" => t(""), 
     '#default_value' => 'Given Name', 
     '#attributes' => array (
      'onblur' => "if (this.value == '') {this.value = 'Given Name'}", 
      'onfocus' => "if (this.value == 'Given Name') {this.value = ''}", 
     ), 
    ); 

    $form['profile_testing_candidate']["field_candidate_family_name"] = array(
     "#title" => "", 
     "#type" => "textfield", 
     "#required" => FALSE, 
     "#description" => t(""), 
     '#default_value' => 'Family Name', 
     '#attributes' => array (
       'onblur' => "if (this.value == '') {this.value = 'Family Name'}", 
       'onfocus' => "if (this.value == 'Family Name') {this.value = ''}", 
     ), 
    ); 
}