2011-10-05 17 views
0

我有一个从数据库中填充的下拉列表。它工作正常,但在视图文件中的form_dropdown中,我想添加class =“required”来验证使用Jquery的下拉菜单。我试图让它工作,但事实证明这是行不通的。你能否帮我准确地把class =“required” - 然后进行jquery验证工作?在form_dropdown中add-class =“required”(jquery validation)的位置?

由于提前

我有这个在我的控制器

// To get the batch name 
$this->load->model('dropdown_batchlist'); 
$data['dropdown_batchlist']= $this->dropdown_batchlist->dropdown_batchlist(); 

这在我的模型 -

function dropdown_batchlist() { 
    $this->db->select('batchname, batchid'); 
    $records=$this->db->get('batch'); 

     $data=array(); 

    // add it here as the first item in the array, 
    // assuming you don't have a $row->batchid of 0 in your results. 
    $data[0] = 'SELECT'; 

    foreach ($records->result() as $row) 
    { 
    $data[$row->batchid] = $row->batchname; 
    } 

return ($data); 
} 

而这在我看来,文件

<?php echo form_dropdown('batchid', $dropdown_batchlist,'', 'class="required"'); ?> 

的问题是Solv编号

我已经找到了问题。视图文件没问题,我只需要替换$ data [0] ='SELECT';与 $ data [''] ='选择';

由于

回答

0

尝试设置使用关联数组的属性:

$attributes = array(
    'name' => 'batchid', 
    'class' => 'required', 
    'options' => $dropdown_batchlist 
); 
echo form_dropdown($attributes);