Skip to content

Commit

Permalink
Merge pull request #32 from drsdre/patch-1
Browse files Browse the repository at this point in the history
Add property emptyMsg
  • Loading branch information
kartik-v committed Nov 14, 2015
2 parents 89f93a0 + 59a5512 commit 21c1279
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ View the [plugin documentation](http://plugins.krajee.com/dependent-dropdown) an
```
{group-name: {id: <option-value>, name: <option-name>}}
```

When no data is available for a specific situation (like an backend error), you can send a custom emptyMsg

```
{emptyMsg: '<your message>'}
```

## Installation

Expand Down Expand Up @@ -350,4 +356,4 @@ $('#input-id').depdrop('init');

## License

**dependent-dropdown** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.
**dependent-dropdown** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.
18 changes: 10 additions & 8 deletions js/dependent-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,22 @@
},
success: function (data) {
selected = isEmpty(data.selected) ? (self.initVal === false ? null : self.initVal): data.selected;
if (isEmpty(data)) {
addOption($el, '', vNullMsg, '');
if (!isEmpty(data.emptyMsg)) {
vNullMsg = data.emptyMsg;
}
if (isEmpty(data) || isEmpty(data.output) || Object.keys(data.output).length == 0) {
$el.html('');
addOption($el, 0, vNullMsg, '');
}
else {
$el.html(self.getSelect(data.output, vDefault, selected));
if ($el.find('optgroup').length > 0) {
$el.find('option[value=""]').attr('disabled', 'disabled');
}
if (data.output) {
if (selected && $.isArray(selected) && $el.attr('multiple')) {
$el.val(selected);
}
$el.removeAttr('disabled');
if (selected && $.isArray(selected) && $el.attr('multiple')) {
$el.val(selected);
}
$el.removeAttr('disabled');
}
optCount = $el.find('option').length;
if ($el.find('option[value=""]').length > 0) {
Expand Down Expand Up @@ -220,4 +222,4 @@
$(function () {
$('select.depdrop').depdrop();
});
}(window.jQuery));
}(window.jQuery));

0 comments on commit 21c1279

Please sign in to comment.