-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to change the "no existing match" label, and selecting it does nothing #216
base: master
Are you sure you want to change the base?
Conversation
… from updating if that item is selected
I like it. It would be nice to have the additional possibility to globally set the label though. |
I agree. I'll put it on my to-do list. Thanks. |
@gfaraj Because, I'm not using this input box only for the model related to auto-complete but also the columns in other tables, too. |
@megalomania1982 you would have to grab my changes since it hasn't been merged yet. No idea who controls that in this repo. If you get my changes, you could probably set the label text to an empty string, and that should be good enough for you. |
@gfaraj Thanks. but how can I grab your version? I have |
Nope, since it hasn't been merged to master you can't do that. You would have to manually replace the autocomplete-rails.js file that you have installed in your gem with the version in this pull request. |
@gfaraj Just replacing the whole content of one file??? which file and where is the content that my file has to be?? Sorry for this noob question. |
The file is autocomplete-rails.js. Run the following command: It will give you the path to the autocomplete gem you have installed. In its parent path there's assets/javascripts. That's where you need to replace autocomplete-rails.js. For example: This is the new content: Note: Make a backup of the original js file in case you want to go back to the old version. |
@gfaraj Thanks for detailed explanation. I followed your instruction and I'm pretty sure that I've done perfect.
But it still pops up the message saying "no existing match" |
Well, yeah, you have to pass the :no_matches_label parameter to autocomplete_field_tag. See my first comment above. Pass in an empty string to that and see what happens. |
@gfaraj I tried to add
|
@gfaraj If possible, could you please check my question? |
I wonder if it works if you set the matches label to ' ' (one space) instead of an empty string. |
@gfaraj is there any old version it didn't show "no existing match"? |
@gfaraj please check and see it again, It's empty. not one space:) |
show "no existing match" |
@megalomania1982 I meant, try it with one space instead of an empty string. Does that remove the text? @dimanlin it hasn't been merged yet, so you can't use it like that. I don't know when it's gonna be merged. |
@gfaraj I tried that. But the same result :( |
@gfaraj I'd say it's not because of the update in this gem.... However, the same result... It still shows this message.... I want to know what to fix... |
Maybe not the best solution, but it works: def get_autocomplete_items parameters
resp = super(parameters)
if resp.blank?
resp = [OpenStruct.new(id: '', label: '')]
end
resp
end with this it returns blank object inside array, instead of blank array. It will show nothing inside 'li' tag instead of 'no existing matches', and 'li' tag will be without any classes. |
@maxrails Thanks for an advice. It still says "null" :( |
strange for me it shows nothing inside but what about css trick - 'li' tag shouldn't contain any classes when nothing inside - so maybe smth like this may help: ul.ui-autocomplete
li
:display none
li.ui-menu-item
:display block |
@maxrails Thanks for an advice it didn't work either. Even if there are matching records, it won't show candidate but it shows thin rectangle. |
This variation on @maxrails solution works for me. Put the following in your ApplicationController. def get_autocomplete_items(parameters)
super(parameters).presence || [OpenStruct.new(id: '', parameters[:method].to_s => '')]
end If you only want to replace the "no existing match" message with your own, then replace the second value in the OpenStruct constructor with a string containing the message you want. If you want the menu to disappear when there are no matches, run the following after page load or if you're doing AJAX, after the response has rendered. Coffeescript: $(autocomplete_field_selector).on 'autocompleteresponse', (event, ui) ->
$(this).autocomplete('close') if ui.content?[0].id.length == 0 Javascript: $(autocomplete_field_selector).on('autocompleteresponse', function(event, ui) {
var content;
if (((content = ui.content) != null ? content[0].id.length : void 0) === 0) {
$(this).autocomplete('close');
}
}); |
@edsimpson Thanks man! It worked perfectly! |
The input's value shouldn't be changed to "no existing match" if clicked, since it's not a valid item. I've fixed this.
Also, you can provide a "data-no-matches-label" attribute on the autocomplete input which specifies the text that will be shown if there are no matches.
<%= autocomplete_field_tag :user_name, '', autocomplete_user_name_users_path, :id_element => '#user_id', :data => { :no_matches_label => 'No matches found' } %>
For the future, we could have the label passed as a special hash value parameter.