如何将cjuidailog框中的选定数据添加到文本框中?

时间:2013-02-22 06:47:48

标签: php yii

如何将cjuidailog框中的选定数据添加到文本框中?

状态:添加项目的表单。 这是项目列表。 enter image description here

当我点击第一行的HS代码时。弹出框(CJUiDialog框)将出现。 enter image description here

我选择了Poly。项目列表将显示如下。 enter image description here

然后我点击第三行的HS代码。弹出框(CJUiDialog框)将出现。然后我选择"按钮"。那时,按钮的数据填充到第一行和第三行,如下所示。 enter image description here

这是视图表

<?php

            for($i=1; $i < 5; $i++)
            {
                ?>
                <tr>
                    <td><input type="text" style="width: 25px;" id="item_no_1_<?php echo $i; ?>"></td>
                    <td><input type="text" style="width: 90%;"></td>
                    <td>
                        <div id="loadingdiv<?php echo $i; ?>" style="float:left; margin-right:0px; width:25px;">&nbsp;</div>
                        <?php echo CHtml::ajaxLink(Yii::t('hs_code','HS Code'),$this->createUrl('hsCode/listing', array('txt_name' =>$i )),array(
                            //'onclick'=>'alert('.$i.');',//$("#hscode'. $i .'").dialog("open"); return false;',
                            'update'=>'#hscode'. $i,
                            'beforeSend' => 'function() {           
                                $("#loadingdiv'. $i .'").addClass("ajaxloading");
                            }',
                            'complete' => 'function() {
                                $("#loadingdiv'. $i .'").removeClass("ajaxloading");
                            }', 
                            ),array('id'=>'showhscodelist' . $i, 'class'=>'btn btn-primary', 'style'=>'float:left; margin-right: 10px;','title'=>'HS Code'));?>   
                        <input type="text" style="width: 70%; float:left;" name="item_description_<?php echo $i; ?>" id="item_description_<?php echo $i; ?>">
                        <div id="hscode<?php echo $i; ?>"></div>
                    </td>
                    <td class="mpz" style="width: 60px;">
                        <input type="text" style="width: 50px;" id="hs_code_pre_<?php echo $i; ?>" name="hs_code_pre_<?php echo $i; ?>" maxlength="6" class="hs_code_pre" readonly>
                    </td>
                    <td class="mpz" style="width: 30px;">
                        <input type="text" style="width: 20px;" id="hs_code_mid_<?php echo $i; ?>" name="hs_code_mid_<?php echo $i; ?>" class="hs_code_mid" maxlength="2" readonly>
                    </td>
                    <td class="mpz" style="width: 30px;">
                        <input type="text" style="width: 20px;" id="hs_code_post_<?php echo $i; ?>" name="hs_code_post_<?php echo $i; ?>" class="hs_code_post" maxlength="2" readonly>
                    </td>
                    <td class="mpz" style="width: 60px;">
                        <input type="text" style="width: 40px;" id="unit_pre_<?php echo $i; ?>" name="unit_pre_<?php echo $i; ?>" maxlength="6">
                    </td>
                    <td class="mpz" style="width: 30px;">
                        <input type="text" style="width: 20px;" id="unit_mid_<?php echo $i; ?>" name="unit_mid_<?php echo $i; ?>" maxlength="2">
                    </td>
                    <td class="mpz" style="width: 30px;">
                        <input type="text" style="width: 20px;" id="unit_post_<?php echo $i; ?>" name="unit_post_<?php echo $i; ?>" maxlength="2">
                    </td>
                </tr>
                <?php 
            }

            ?>

这是hscode / listing(控制器)

public function actionListing()
    {
        $model=new HsCode('search');
        $model->unsetAttributes();  // clear any default values
        if(isset($_GET['HsCode']))
            $model->attributes=$_GET['HsCode'];
        //unset($txt_name);

        if(isset($_GET['txt_name']))
            $txt_name = $_GET['txt_name'];

        //unset($_GET['txt_name']);

        $this->renderPartial('hscode_listing',array('model'=>$model, 'txt_name'=>$txt_name),false,true);
    }

这是views / hs_code / hscode_listing

<?php 
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
                'id'=>'hscode' . $txt_name,
                'options'=>array(
                    'title'=>Yii::t('hscode' . $txt_name,'H.S Code List'),
                    'autoOpen'=>true,
                    'modal'=>'true',
                    'width'=>'950',
                    'height'=>'500',
                ),
                ));
?>
<?php $this->renderPartial('_hscode_listing', array('model'=>$model, 'txt_name'=>$txt_name)); ?>


<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>

这是_hscode_listing

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'hs-code-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,       
    'columns'=>array(
        array(
            'name'=>'code',
            'header'=>'HS Code',
            'value'=>'$data->code',
            'htmlOptions'=>array('class'=>'hs_code'),  
        ),

        array(
            'name'=>'description',
            'header'=>'Description',    
            'value'=>'$data->description',
            'htmlOptions'=>array('class'=>'description'),
        ),
        array(
            'name'=>'id_rate',
            'header'=>'Import Duty Rate',   
            'value'=>'$data->id_rate',
            'htmlOptions'=>array('class'=>'id_rate'),
        ),
        array(
            'name'=>'ct_rate',
            'header'=>'C.T Rate',   
            'value'=>'$data->ct_rate',
            'htmlOptions'=>array('class'=>'ct_rate'),
        ),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{select}',
            'buttons'=>array
            (
                'select' => array
                (
                    'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/icon_select.gif',
                    'options'=>array('style'=>'width:10px; border:none'),
                    'click'=>'function(){
                        alert( ' . $txt_name . ');
                        var hs_code = $(this).parents(\'tr\').find(\'.hs_code\').text();                        
                        var hscode_pre = hs_code.substr(0,6);
                        var hscode_mid = hs_code.substr(6,2);
                        var hscode_post = hs_code.substr(8,2);
                        var description = $(this).parents(\'tr\').find(\'.description\').text();
                        var id_rate = $(this).parents(\'tr\').find(\'.id_rate\').text();
                        var ct_rate = $(this).parents(\'tr\').find(\'.ct_rate\').text();
                        //var temp = $("#item_des").val(itemID);
                        $("#hs_code_pre_'.$txt_name.'").val(hscode_pre);
                        $("#hs_code_mid_'.$txt_name.'").val(hscode_mid);
                        $("#hs_code_post_'.$txt_name.'").val(hscode_post);
                        $("#item_description_'.$txt_name.'").val(description);
                        $("#id_rate_'.$txt_name.'").val(id_rate);
                        $("#ct_rate_'.$txt_name.'").val(ct_rate);
                        $("#hscode' . $txt_name .'").dialog("close");
                    }',
                ),      
            ),
        ),
        array(
            'type'=>'raw',
            'value'=>'$data->id',
            //'filter'=>array('style'=>'visible:none'), 
            'headerHtmlOptions'=>array('style'=>'width:0px; display:none; border:none; textdecoration:none'),
            'htmlOptions'=>array('style'=>'display:none; border:none;', 'class'=>'recei-id'),  
            'header'=>false,
            //'filter'=>false,
        ),
    ),
)); ?>


<style>
#jobs-grid td:last-child, #jobs-grid th:last-child {display: none}
</style>

ံ如何解决我的问题,如何将选定数据从cjuidailog框添加到文本框而不是2个位置?

THX

0 个答案:

没有答案