且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

与爵士,但没有显示在提交的数据更新表单字段

更新时间:2023-10-05 23:46:16

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

在我静看我现在刚< 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.