Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created April 2, 2012 21:04
Show Gist options
  • Save coderforhire/2287184 to your computer and use it in GitHub Desktop.
Save coderforhire/2287184 to your computer and use it in GitHub Desktop.
jQuery(function() {
var a;
return $("#ticket_branch_id").parent().hide(), a = $("#ticket_branch_id").html(), $("#ticket_client_id").change(function() {
var b, c, d;
return b = $("#ticket_client_id :selected").text(), c = b.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, "\\$1"), d = $(a).filter("optgroup[label='" + c + "']").html(), d ? ($("#ticket_branch_id").html(d), $("#ticket_branch_id").parent().show()) : ($("#ticket_branch_id").empty(), $("#ticket_branch_id").parent().hide())
})
})
@coderforhire
Copy link
Author

jQuery ->
$('#ticket_branch_id').parent().hide()
branches = $('#ticket_branch_id').html()
$('#ticket_client_id').change ->
client = $('#ticket_client_id :selected').text()
escaped_client = client.replace(/([ #;&,.+*~':"!^$=>|/@])/g, '$1')
options = $(branches).filter("optgroup[label='#{escaped_client}']").html()
if options
$('#ticket_branch_id').html(options)
$('#ticket_branch_id').parent().show()
else
$('#ticket_branch_id').empty()
$('#ticket_branch_id').parent().hide()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment