In a form override partial (e.g., _#{columnname}_form_column.rhtml):
<dl>
<dt><label for="<%= "record_#{column.name}" %>"><%= column.label %></
label></dt>
<dd>
<%= text_field_with_auto_complete
active_scaffold_config.model.to_s.underscore, column.name, :class =>
'text-input'%>
<span class="description"><%= column.description %></span>
</dd>
</dl>
in the controller:
auto_complete_for :#{model_name}, :#{column_name}
For instance I have:
app/views/lab_resources/_cpu_form_column.rhtml with the above HTML/ERB
exactly and
app/controllers/lab_resources_controller with the line:
auto_complete_for :lab_resource, :cpu
Is there any way you can roll it into your own form.ui stuff ?
On Oct 2, 11:36 pm, Robin <rdwhee...@rsglobal.net> wrote:
> Trying to createautocompletefields in AS gave me some headaches, but
> here is an easy way to makeautocompletetext fields that fit right in
Go for it !
I had issues with the text-input so much show that I have not
implemented my own
form.ui=:text_input support :-)
> > auto_complete_for :lab_resource, :cpu- Hide quoted text -
>
> - Show quoted text -
<%
column_name = column.name
field_value = @record[column_name
field_name = "record[#{column_name}]"
field_id = "record_#{column_name}"
field_class = "#{column_name}-input text-input"
model_name = active_scaffold_config.model.to_s.underscore
autocomplete_id =
"record_#{column_name}_auto_complete_#{@record[:id]}"
autocomplete_url = url_for(:controller =>
model_name.pluralize, :action =>
"auto_complete_for_#{model_name}_#{column_name}")
autocomplete_param_name = "#{model_name}[#{column_name}]"
%>
<dl>
<dt><label for="<%=field_id%>"><%=column.label%></label></dt>
<dd>
<%=text_field_tag field_name, field_value, :id => field_id, :class
=> field_class%>
<div class="auto_complete <%=field_class%>" id="<%=autocomplete_id
%>"></div>
<%= javascript_tag("new Ajax.Autocompleter('#{field_id}',
'#{autocomplete_id}', '#{autocomplete_url}', {paramName:
'#{autocomplete_param_name}', fullSearch: true, frequency: 0,
minChars: 2})") -%>
</dd>
</dl>
But the autocomplete result don't get the class from own field
Awesome, Robin!
This is 99% of something I was looking to do just yesterday.
The other 1% is limiting the auto-complete values based on the current
user. I've got a method which pulls out the values I want, and
ideally would like to pass that to the auto_complete list, but can't
figure out how to do that...
Ideas, anyone?
Thanks, in advance,
jmb-d
On Oct 5, 6:42 pm, "Antonio Bardazzi Multicore-Sistemi.com"
def active_scaffold_input_autocomplete(column, options)
column_name = column.name
field_value = @record[column_name]
field_name = "record[#{column_name}]"
field_id = "record_#{column_name}"
field_class = "#{column_name}-input text-input"
model_name = active_scaffold_config.model.to_s.underscore
autocomplete_id =
"record_#{column_name}_auto_complete_#{@record[:id]}"
autocomplete_url = url_for(:controller =>
model_name.pluralize, :action =>
"auto_complete_for_#{model_name}_#{column_name}")
autocomplete_param_name = "#{model_name}[#{column_name}]"
tag = text_field_tag field_name, field_value, :id =>
field_id, :class => field_class
js = javascript_tag("new Ajax.Autocompleter('#{field_id}',
'#{autocomplete_id}', '#{autocomplete_url}', {paramName:
'#{autocomplete_param_name}', fullSearch: true, frequency: 0,
minChars: 2})")
"#{tag}<div class=\"auto_complete\" id=\"#{autocomplete_id}
\"></div>#{js}<span class=\"description\">#{column.description}</span>
</dd> </dl>"
end
It seems work but I don't know if has some side effects.
On Oct 7, 3:30 am, "Antonio Bardazzi Multicore-Sistemi.com"
- Hide quoted text -
- Show quoted text -
cch: Did just that and added to one of my controllers for a text-
input
column
config.columns[:bill_no].form_ui = :autocomplete
save
restart server
Result : No error message but no auto-completion :-)
CCH
http://cch4rails.blogspot.com
On Oct 7, 3:30 am, "Antonio Bardazzi Multicore-Sistemi.com"
> > > But the autocomplete result don't get the class from own field- Hide quoted text -
Watch the log and debug with logger.info for see what is happening:
active_scaffold_input_autocomplete is called ?
Use firefox firebug->net params/response to see if your
auto_complete_for_#{model}_#{column_name} is called with right params
> CCHhttp://cch4rails.blogspot.com
Do you have a simple project that shows how the auto-completion is
supposed to work ?
If so,can you upload it in the Files Section of this group?
TIA
On Oct 7, 5:52 pm, "Antonio Bardazzi Multicore-Sistemi.com"
> > > - Show quoted text -- Hide quoted text -
If so could you tell me what you did as I am trying everything in the
_form.rhtml override but with no success.
TIA
I am really stuck as most examples of autocomplete on the web use the
url for an action and I can't do this with AS.
I suppose I can still capture what is genrated in FireBug and work
backwards but I can't get autocomplete to work on even simple
examples.
eg "products" table and "colour" field
Thanks
If I use the this in my _form.rhtml override for product then it
works.
<li class="form-element">
<dl>
<dt>
<label for="record_colour">Colour</label>
</dt>
<dd>
<%= text_field_with_auto_complete :product, :colour %>
</dd>
</dl>
</li>
and have
auto_complete_for :product, :colour
In the product controller.
However the id and name attributes that it generates are not desirable
as the AS obviously does not accept that naming convention.
Here is how one form element should look.
<li class="form-element">
<dl>
<dt>
<label for="record_price">Price</label>
</dt>
<dd>
<input type="text" autocomplete="on" class="price-input text-
input" id="record_price" name="record[price]" maxlength="15" size="15"
value=""/>
</dd>
</dl> </li>
But the <%= text_field_with_auto_complete :product, :colour %> ruby
statement is generating the code below.
I have typed in "B" and it correctly generates the auto-suggest area.
<li class="form-element">
<dl>
<dt>
<label for="record_colour">Colour</label>
</dt>
<dd>
<style type="text/css"> div.auto_complete {
width: 350px;
background: #fff;
}
div.auto_complete ul {
border:1px solid #888;
margin:0;
padding:0;
width:100%;
list-style-type:none;
}
div.auto_complete ul li {
margin:0;
padding:3px;
}
div.auto_complete ul li.selected {
background-color: #ffb;
}
div.auto_complete ul strong.highlight {
color: #800;
margin:0;
padding:0;
}
</style><input type="text" size="30" name="product[colour]"
id="product_colour" autocomplete="off"/><div
id="product_colour_auto_complete" class="auto_complete"
style="position: absolute; left: 584px; top: 529px; width: 206px;
opacity: 0.999999; display: none;"><ul><li class="selected">Blue</
li><li>Black</li><li>Brown</li></ul></div>
</dd>
</dl>
</li>
I have captured what it generates (basically the above code) and
modified it slightly to try and get and override so that I can format
the <input ...> tag.
This is my whole reason for doing so.
Can anyone tell me how to get this working as I am most frustrated and
have spend 3 days on it with no success.
Thanks for any help in advance.
Uncle Mike
Has anyone got an idea how I can get this autosuggest working with a
form override has I have tried using Firebug to copy the generated
code and paste it back into the _form.rhtml of product but this is not
working.
Please can someone out there help me in this moment of crises.
http://www.dcs.lancs.ac.uk/~grill/mgbox/
But it is in PHP.
Has anyone got the autosuggest working for a full form override?
TIA