Skip to content

Commit

Permalink
Show indication in filtering-multiselect widget to reduce confusion
Browse files Browse the repository at this point in the history
Fixes #1369
  • Loading branch information
mshibuya committed Jul 15, 2015
1 parent 5aafa20 commit a515b37
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
25 changes: 20 additions & 5 deletions app/assets/javascripts/rails_admin/ra.filtering-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
chooseAll: "Choose all",
chosen: "Chosen records",
clearAll: "Clear all",
remove: "Remove",
selectChoice: "Select your choice(s) and click"
remove: "Remove"
},
searchDelay: 400,
remote_source: null,
Expand Down Expand Up @@ -101,6 +100,13 @@
this.selection.wrap('<div class="wrapper"/>');

this.element.css({display: "none"});

this.tooManyObjectsPlaceholder = $('<option disabled="disabled" />').text(RailsAdmin.I18n.t("too_many_objects"));
this.noObjectsPlaceholder = $('<option disabled="disabled" />').text(RailsAdmin.I18n.t("no_objects"))

if(this.options.xhr){
this.collection.append(this.tooManyObjectsPlaceholder);
}
},

_bindEvents: function() {
Expand Down Expand Up @@ -164,13 +170,21 @@
var widget = this;
widget._query(val, function(matches) {
var i;
widget.collection.html('');
var filtered = [];
for (i in matches) {
if (matches.hasOwnProperty(i) && !widget.selected(matches[i].id)) {
filtered.push(i);
}
}
if (filtered.length > 0) {
widget.collection.html('');
for (i in filtered) {
widget.collection.append(
$('<option></option>').attr('value', matches[i].id).attr('title', matches[i].label).text(matches[i].label)
);
}
} else {
widget.collection.html(widget.noObjectsPlaceholder);
}
});
},
Expand Down Expand Up @@ -209,10 +223,11 @@
matches.push({id: i, label: this._cache[i]});
}
}
success.apply(this, [matches]);
} else {
this.collection.html(this.tooManyObjectsPlaceholder);
}

success.apply(this, [matches]);

} else {

if (this.options.xhr) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/rails_admin/ra.i18n.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class @RailsAdmin
@RailsAdmin.I18n = class Locale
@init: (@locale)->
@t:(key) ->
humanize = key.charAt(0).toUpperCase() + key.replace("_", " ").slice(1)
humanize = key.charAt(0).toUpperCase() + key.replace(/_/g, " ").slice(1)
@locale[key] || humanize
2 changes: 2 additions & 0 deletions config/locales/rails_admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ en:
is_exactly: Is exactly
starts_with: Starts with
ends_with: Ends with
too_many_objects: "Too many objects, use search box above"
no_objects: "No objects found"
loading: "Loading..."
toggle_navigation: Toggle navigation
home:
Expand Down

2 comments on commit a515b37

@dalpo
Copy link
Contributor

@dalpo dalpo commented on a515b37 Jul 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎆 Thanks @mshibuya!

@fmh
Copy link
Contributor

@fmh fmh commented on a515b37 Jul 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double click on disabled option work, and give this error !
capture d ecran 2015-07-15 a 19 47 28

just edit ra.remote-form.js line 22 to resolve this
dom_widget.on('dblclick', '.ra-multiselect option:not(:disabled)', function(e){

Please sign in to comment.