简体   繁体   English

自动完成:根据选择填充多个字段

[英]Autocomplete: populate multiple fields based on selection

I have a form, and there are 5 fields. 我有一个表格,有5个字段。 The first field is an autocomplete field. 第一个字段是自动完成字段。 I'd like to have the other 4 fields populated based on the autocomplete field selection. 我想根据自动完成字段选择填充其他4个字段。 The docs in github ajax.autocompleter page reference setting an id and using a js function to call the id value, but this doesn't seem efficient if using multiple fields/need multiple values in addition to the ac value. github ajax.autocompleter页面中的文档设置了一个id并使用js函数来调用id值,但是如果使用多个字段/除ac值之外还需要多个值,这似乎并不高效。

I'm using scriptaculous, and php. 我正在使用scriptaculous和php。 I have the autocompleter functioning, but am not sure on the rest of it. 我具有自动完成功能,但不确定其余功能。 I'm also not clear on how to set the additional field parameters on the php end. 我也不清楚如何在php端设置其他字段参数。 I suppose that I could set the id="field1Val='blah'&field2Val='blah2'" then use js to parse and populate fields, but something about that just doesn't feel right. 我想我可以设置id =“ field1Val ='blah'&field2Val ='blah2'”,然后使用js解析和填充字段,但是那种感觉并不对。

Any idears? 有想法吗?

this is what we use: a jquery plugin . 这就是我们使用的: jquery插件 The good thing about this one is that you can add a callback function that allow you to change the "current" behavior. 关于这一点的好处是,您可以添加一个回调函数,该函数允许您更改“当前”行为。

about the line 385 you have function that parses the result: 关于第385行,您具有解析结果的函数:

function parse(data) {
    var parsed = [];
    var rows = data.split("\n");
    for (var i=0; i < rows.length; i++) {
        var row = $.trim(rows[i]);
        if (row) {
            row = row.split("|");
            parsed[parsed.length] = {
                data: row,
                value: row[0],
                result: options.formatResult && options.formatResult(row, row[0]) || row[0]
            };
        }
    }
    return parsed;
};

you can create your own function that depending on what you get (you can send a json from the server) and then execute javascript and drive the form controls. 您可以创建自己的函数,具体取决于获得的内容(可以从服务器发送json),然后执行javascript并驱动表单控件。

hope help you 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM