在提交的数据的js,但没有显示更新表单字段(update form field with js bu

2019-10-29 06:50发布

在CakePHP的2.0 JsHelper尝试,我有一个请求方法来更新AJAX调用的结果的表单字段的值 - 到目前为止,那么好。 然而,在检查表单域,它说:

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

但是当我复制并粘贴首先它上面它说

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

当我提交表单的值是空的。 为什么浏览器显示的值,但底层的DOM不登记吗?

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

编辑如这里要求是形式的数据转储

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

这里是AJAX代码

$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
            ))
        )
    )
);

Answer 1:

您需要设置值属性:

<input type="hidden" value="YOUR VALUE HERE" name="data[Etc][field]" />

你不裹在输入标签的值。



Answer 2:

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

在我的静态视图我现在有刚<td id="part"></td>其中输入字段是。 我的Ajax现在呼叫更新“ #part ”和我的动态视图(一个由控制器AJAX动作称为)现在输出的整个领域- <?php echo $this->Form->input('unitcost', array('type' => 'text', 'value' => $part['Part']['costamount'])); ?> <?php echo $this->Form->input('unitcost', array('type' => 'text', 'value' => $part['Part']['costamount'])); ?> 。 丑陋,但它的工作原理。



Answer 3:

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

);



文章来源: update form field with js but not showing in submitted data