与爵士,但没有显示在提交的数据更新表单字段 [英] update form field with js but not showing in submitted data

查看:100
本文介绍了与爵士,但没有显示在提交的数据更新表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与JsHelper在CakePHP中2.0进行实验,我有一个请求方法来更新与AJAX调用结果的表单字段的值 - 到目前为止,一切都很好。然而,在检查表单域,它说:

 <输入类型=隐藏ID =JobsPartUnitcostNAME =数据[JobsPart] [unitcost]> 5.55< /输入>
 

但是当我将它复制并粘贴第一上面它说

 <输入类型=隐藏ID =JobsPartUnitcostNAME =数据[JobsPart] [unitcost]>< /输入>
 

当我提交表单的值是空的。为什么在浏览器中显示出的价值,但底层的DOM没有注册吗?

使用Mac / Safari浏览器,CakePHP的2.0,JQuery的

修改 由于这里要求的是表格数据转储

 阵列([JobsPart] =>阵列([JOB_ID => 1 [的company_id] => 4 PART_ID] => 2 [数量] = 1→3 [unitcost] =>))
 

这里是AJAX code

  $这个 - > Js->获得('#JobsPartPartId') - >事件('变',
    $这个 - > Js->请求(
        阵列(
            控制器=>JobsParts,
            '行动'=>'getPart
        ),
        阵列(
            更新=>#JobsPartUnitcost,
            异步=>真正,
            '方法'=> 邮报,
            dataEx pression'=>如此,
            '数据'=> $这个 - > Js-> serializeForm(阵列(
                isForm'=>假,
                内联=>真正
            ))
        )
    )
);
 

解决方案

确定。我已经找到了解决办法,并没有其他人似乎找到了一个直接的解决方案。

在我静看我现在刚< TD ID =一部​​分>< / TD> ,其中输入域了。我的Ajax调用现在更新' #part 我的动态视图(一个叫由控制器AJAX动作)现在输出的整个领域 - < ?PHP的echo $这个 - >形式 - >输入('unitcost',阵列('类型'=>'文字','价值'=> $部分['部分'] ['costamount'])) ; ?> 。丑陋,但它的工作原理。

Experimenting with JsHelper in CakePHP 2.0, I got a Request method to update the value of a form field with the results of an AJAX call - so far, so good. However, on inspecting the form field it says:

<input type="hidden" id="JobsPartUnitcost" name="data[JobsPart][unitcost]">5.55</input>

but when I copied it and first pasted it above it said

<input type="hidden" id="JobsPartUnitcost" name="data[JobsPart][unitcost]"></input>

and when I submitted the form the value was empty. Why is the browser showing the value but the underlying DOM not registering it?

Using Mac/Safari, CakePHP 2.0, JQuery

EDIT As requested here is form data dump

    Array ( [JobsPart] => Array ( [job_id] => 1 [company_id] => 4 [part_id] => 2 [qty] => 3 [unitcost] => ) )

and here is AJAX code

$this->Js->get('#JobsPartPartId')->event('change',
    $this->Js->request(
        array(
            'controller'=>'JobsParts',
            'action'=>'getPart'
        ),
        array(
            'update'=>'#JobsPartUnitcost',
            'async' => true,
            'method' => 'post',
            'dataExpression'=>true,
            'data'=> $this->Js->serializeForm(array(
                'isForm' => false,
                'inline' => true
            ))
        )
    )
);

解决方案

OK. I have found a workaround and no one else seems to have found a direct solution.

In my static view I now have just <td id="part"></td> where the input field was. My Ajax call now updates '#part' and my dynamic view (the one called by the controller ajax action) now outputs the whole field - <?php echo $this->Form->input('unitcost', array('type' => 'text', 'value' => $part['Part']['costamount'])); ?>. Ugly but it works.

这篇关于与爵士,但没有显示在提交的数据更新表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆