开发者

Problem with Auto Complete Concept in Symfony

I am working on a Symfony application that works mainly with form submissions and our team needed extreme customisation on validations therefore we chose to not use the forms helper and widgets. Now each form has an action method for submission and retrieval. In between one of those forms I need an auto fill but I don't know how I should send this to a new action method on the keyup event and return data from there. I am completely unable to return the data from there I have checked using Firebug. I have found articles that submit the whole form for a search auto fill. I can't do that because my auto fill field is not the only one on the form. It's a city field which I have to give suggestions on. I am expected to use the jQuery framework. Please help.

Moreover I don't understand the AJAX concept in Symfony ve开发者_运维知识库ry well. It would be really helpful if you could link me to some good articles.

Appreciate all the help. Thanks a lot.


The main difference of response in Symfony for ajax request is the action wouldn't decorate the view (actionSucces.php) with the Layout (so it won't include the web debug toolbar either).

In your case, you can use the jQuery Autocomplete plugin (http://docs.jquery.com/Plugins/autocomplete) to produce your extreme customisation form :D

you can use slot to define your jQuery object definition in layout

<head>
    <?php if (has_slot('head_script')): ?>
    <?php    include_slot('head_script') ?>
    <?php endif ?>
 </head>

define your jQuery Autocomplete in the extreme customisation form template

<?php slot('head_script')  ?>
<?php echo javascript_tag('$(function{
$("#example").autocomplete("'.url_for('search/cities').'");
});') ?>

<?php echo form_tag('form/result') ?>
<?php echo tag('input', array('name'=>'example','id'=>'example'));
</form>

don't forget to include your jQuery and Autocomplete plugins, when user start typing a request sent to specified backend with a GET parameter q that contains the current value of the input box and a parameter "limit" with the value specified for the max option. (please refer to the doc :D )

now create action search/cities and use $request->getParameter('q') to populate the response

public function executeCities(sfWebRequest $request){
  //process the $request->getParameter('q')
  return $this->renderText("First Second Third Fourth");
}

cheers and happy new year :D

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜