Skip to content

## Version 1.2.2 #32

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# jQuery Dependent Selects Change Log

## Version 1.2.2

- Allow placeholder value for sub selects through a passed array of strings
- Fixes a display bug when form displays a hirer hierarchy choice (attr -> prop)
- Fixes that undefined caused an exception to exit when initially displaying the selection value


## Version 1.2.1

- Fixes a display bug with placeholder selects and labels not displaying at the correct times
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ $('.example-class').dependentSelects({
placeholderOption: '', // String or array of strings: The text used for the sub select boxes' placeholder option.
// If an array, the first 'sub' level will be the first array item, you should manually create
// the top level's placeholder in the HTML.
placeholderValue: '', // String or array of strings: The value used for the sub select boxes' placeholder option.
placeholderSelect: false, // Array of strings: The text used for placeholder select boxes for sub levels.
class: false, // String: Add an extra class to all sub selects
labels: false // Array of strings: The text used for the sub select boxes' labels. Label element is
Expand Down
31 changes: 23 additions & 8 deletions jquery.dependent-selects.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###
# jQuery Dependent Selects v1.2.2
# jQuery Dependent Selects v1.2.3
# Copyright 2012 Mark J Smith, Simpleweb
# Licenced under MIT
# Details on http://github.com/simpleweb/jquery-dependent-selects
###

Expand All @@ -10,6 +11,7 @@
options = $.extend({
'separator': ' > '
'placeholderOption': ''
'placeholderValue': ''
'placeholderSelect': false
'class': false
'labels': false
Expand Down Expand Up @@ -68,7 +70,19 @@
text = placeholder[placeholder.length-1]
else
text = placeholder
$("<option>#{text}</option>")

def_val = options.placeholderValue
if typeof def_val == 'object'
if def_val[depth]
val = def_val[depth]
else
val = def_val[def_val.length-1]
else
val = def_val
if val != null && val != ''
val = ' value="' + val + '"';

$("<option#{val}>#{text}</option>")

labelAtDepth = (depth, $select) ->
depth--
Expand Down Expand Up @@ -128,7 +142,7 @@
clearAllSelectsByParent = ($parent) ->
$(".dependent-sub[data-dependent-id='#{$parent.attr('data-dependent-id')}']").each ->
if parseInt($(@).attr('data-dependent-depth')) > parseInt($parent.attr('data-dependent-depth'))
$(@).find('option:first').attr('selected', 'selected')
$(@).find('option:first').prop('selected', true)
hideSelect $(@)

createNewSelect = (name, $select, depth) ->
Expand Down Expand Up @@ -211,13 +225,14 @@
for i in [(parseInt $selected_select.attr('data-dependent-depth'))..0]
$current_select.find('option').each ->
if $(@).html() == current_option_text
$(@).attr('selected', 'selected')
$(@).prop('selected', true)
else
$(@).removeAttr('selected')

$(@).prop('selected', false)
showSelect $current_select
current_option_text = splitName($current_select.attr('data-dependent-path')).slice(-1)[0];
$current_select = findSelectParent($current_select)
if typeof($current_select.attr('data-dependent-path')) != "undefined"
current_option_text = splitName($current_select.attr('data-dependent-path')).slice(-1)[0];
$current_select = findSelectParent($current_select)

$selected_select.trigger('change')

Expand Down
36 changes: 26 additions & 10 deletions jquery.dependent-selects.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.