sfWidgetFormDoctrineJQueryAutocompleter - 事件不起作用

发布于 2024-11-02 19:52:57 字数 1825 浏览 5 评论 0原文

我正在使用 sfFormExtraPlugin 中的 sfWidgetFormDoctrineJQueryAutocompleter,尝试将某些事件绑定到小部件。

根据 http://jqueryui.com/demos/autocomplete/#event-search有一种方法可以将事件绑定到搜索的启动。

但是,它似乎不适用于小部件。 我的代码:

$this->widgetSchema['author_id'] = new sfWidgetFormDoctrineJQueryAutocompleter(array(
  'model'  =>  'Employee',
  'method' => 'getFullName',
  'method_for_query' => 'findOneByEmployeeNumber',
  'url'    =>  '/backend_dev.php/employee/search',
  'config' =>  '{
    minChars: 3,
    search: function(event, ui) { alert("Search!"); } //Should popup an alert() when the search is launched.
    }'
));

但是,当我填写表单时,将启动搜索,显示结果,但不显示警报。

有什么想法吗?

谢谢。

编辑

生成的 Javascript:

<label for="document_author_id">Author</label>
<input type="hidden" id="document_author_id" value="00000006" name="document[author_id]">
<input type="text" id="autocomplete_document_author_id" value="Michaël Jones" name="autocomplete_document[author_id]" autocomplete="off" class="ac_input">
<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery("#autocomplete_document_author_id")
    .autocomplete('/backend_dev.php/employee/search', jQuery.extend({}, {
      dataType: 'json',
      parse:    function(data) {
        var parsed = [];
        for (key in data) {
          parsed[parsed.length] = { data: [ data[key], key ], value: data[key], result: data[key] };
        }
        return parsed;
      }
    }, {
        minChars: 3,
        search: function(event, ui) { alert("Search!"); }
        }))
    .result(function(event, data) { jQuery("#document_author_id").val(data[1]); });
  });
</script>

I'm using the sfWidgetFormDoctrineJQueryAutocompleter from the sfFormExtraPlugin, an try to bind some event to the widget.

According to http://jqueryui.com/demos/autocomplete/#event-search there is a way to bind an event to the launch of a search.

However, it doesn't seems to work on the widget.
My code:

$this->widgetSchema['author_id'] = new sfWidgetFormDoctrineJQueryAutocompleter(array(
  'model'  =>  'Employee',
  'method' => 'getFullName',
  'method_for_query' => 'findOneByEmployeeNumber',
  'url'    =>  '/backend_dev.php/employee/search',
  'config' =>  '{
    minChars: 3,
    search: function(event, ui) { alert("Search!"); } //Should popup an alert() when the search is launched.
    }'
));

However, when I fill the form, the search is launched, results are shown, but no alert is displayed.

Any ideas ?

Thanks.

Edit

Generated Javascript:

<label for="document_author_id">Author</label>
<input type="hidden" id="document_author_id" value="00000006" name="document[author_id]">
<input type="text" id="autocomplete_document_author_id" value="Michaël Jones" name="autocomplete_document[author_id]" autocomplete="off" class="ac_input">
<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery("#autocomplete_document_author_id")
    .autocomplete('/backend_dev.php/employee/search', jQuery.extend({}, {
      dataType: 'json',
      parse:    function(data) {
        var parsed = [];
        for (key in data) {
          parsed[parsed.length] = { data: [ data[key], key ], value: data[key], result: data[key] };
        }
        return parsed;
      }
    }, {
        minChars: 3,
        search: function(event, ui) { alert("Search!"); }
        }))
    .result(function(event, data) { jQuery("#document_author_id").val(data[1]); });
  });
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟柳画桥 2024-11-09 19:52:57

尝试将其放在 form.php (?) 模板的末尾

<?php javascript_tag(); ?>
    jQuery().ready(function(){
        // or use ID #autocomplete_document_author_id
        jQuery(".ac_input").search(function(event, ui){
            alert("Search!");
        });
    });
<?php end_javascript_tag(); ?>

Try to put this at the end of your form.php (?) template

<?php javascript_tag(); ?>
    jQuery().ready(function(){
        // or use ID #autocomplete_document_author_id
        jQuery(".ac_input").search(function(event, ui){
            alert("Search!");
        });
    });
<?php end_javascript_tag(); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文