From 549f8c247ac89e168b8d4431011a29b376bcc4ab Mon Sep 17 00:00:00 2001 From: crivano Date: Thu, 20 Aug 2015 17:04:34 -0300 Subject: [PATCH] Fixed the ".last()" problem and made changes so that we can have selects with options.placeholderOption=false, there is a options.changed function. --- jquery.dependent-selects.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/jquery.dependent-selects.js b/jquery.dependent-selects.js index c8d6534..38ce3e0 100644 --- a/jquery.dependent-selects.js +++ b/jquery.dependent-selects.js @@ -80,6 +80,8 @@ } else { text = placeholder[placeholder.length - 1]; } + } else if (placeholder == false) { + return $(''); } else { text = placeholder; } @@ -194,10 +196,12 @@ path = pathForOption($select, valName).replace("'", "\\'"); if (($sub = $(".dependent-sub[data-dependent-path='" + path + "'][data-dependent-id='" + select_id + "']")).length > 0) { showSelect($sub); - return $sub.attr('name', $select.attr('data-dependent-input-name')); + $sub.attr('name', $select.attr('data-dependent-input-name')); } else { - return $select.attr('name', $select.attr('data-dependent-input-name')); + $select.attr('name', $select.attr('data-dependent-input-name')); } + if (typeof options.changed == 'function' && options.initialized) + options.changed(); }; selectedOption = function($select) { var $selectedOption, val; @@ -245,7 +249,11 @@ } }); showSelect($current_select); - current_option_text = splitName($current_select.attr('data-dependent-path')).last(); + if ($current_select.attr('data-dependent-path') == undefined) + break; + var sn = splitName($current_select.attr('data-dependent-path')); + current_option_text = sn[sn.length-1]; + $current_select = findSelectParent($current_select); } return $selected_select.trigger('change'); @@ -289,7 +297,8 @@ $select.attr('data-dependent-input-name', $select.attr('name')); selectedOption($select); prepareSelect($select, 0, createSelectId()); - return selectPreSelected($select); + selectPreSelected($select); + options.initialized = true; }); }; })(jQuery);