开发者

cakephp observerfield multiple updates

开发者 https://www.devze.com 2023-02-19 23:50 出处:网络
Using CakePHP\'s Ajax based observefield, I would like to update multiple fields, into my form, any idea how can i achieve this?

Using CakePHP's Ajax based observefield, I would like to update multiple fields, into my form, any idea how can i achieve this?

If i try with 'update' => array('NoncompetitorEventId','NoncompetitorEventId') it doesn't work even. It works for single field update, but not for multiple ones.

Kindly let me know if some patch is there. I'm using CakePHP 1.2 versi开发者_开发百科on.

Thanks !


You can do it with little tweak using the prototype along with observe field:

Like:

Step 1: Call your function using observe field and call protype function on complete as follow:

echo $ajax->observeField('TransportorderContactId',array('url'=>'functionname','indicator' => 'loading_message','complete' => 'updateDetails(request,json)'));`

Step 2: Set the required fields in json variable in your called function:

echo json_encode(array('field1' => value1,'field2' => value2); //here keep your field name as id of the field you want to update.

Step 3: Now you will get the above fields in your updateDetails function which is in add.ctp

 <script language="javascript">
   function updateDetails(request,json){
        var data = request.responseText.evalJSON();
        $H(data).each(function(pair){
          $(pair.key).setValue(pair.value);
        });
   }
 </script>

And like this you can update more than one field using observe field.

0

精彩评论

暂无评论...
验证码 换一张
取 消