2014-07-08 65 views
0

我真的陷入了困境,試圖找出如何預先選擇一個選項添加使用addfield下拉。 我添加這樣的文本字段,我可以填充使用:value:'xyz'在字段的數組中。但選擇框不能識別。 任何人都可以請幫忙。 (也,我使用Idealforms 2,不是3) 我的下拉代碼如下所示:Idealforms:預選選項與加號字段

var newFields = [ 
    { 
    name: 'accounttype', 
    label: 'Account type', 
    filters: 'exclude', 
    data: { exclude: ['default'] }, 
    errors: { exclude: 'Please select account type' }, 
    type: 'select', 
    list: [ 
     'Select account type::default', 
     'Current/Cheque::1', 
     'Savings::2', 
     'Transmission::3' 
    ], 
    value: 'Transmission::3', 
    addAfter: 'pay-options' 
}, 

我試過在價值線的所有可能的選項,也試過以後選擇它使用jQuery下面的情況下,其AJAX時間問題。但仍然很困難。請可能有人來看看:)

var my_accounttype = '3';  
    $('#accounttype option').each(function(){ 
     var $this = $(this); 
     if ($this.val() == my_accounttype) { 
      alert ($this.val() + " == " + my_accounttype); 
      $this.prop('selected', true); 
      return false; 
     } 
    }); 

人有什麼想法? V

回答

0

想通了! 一點任務,但在這裏... 所有你需要做的是找到HTML選擇輸入轉換爲idealforms風格列表後的實際元素。然後模擬點擊!

(document).ready(function() { 
     dateforuse = gup('salarydate3'); 
     if(dateforuse[0] == 0){ dateforuse = dateforuse[1]; } //in case date below 10 and leads with a zero 
     $(".salarydate3 li ul li").each(function(index) { 
      if($(this).text() == dateforuse){ 
       $(this).click(); 
      } 
     }); 
});