0

For some reason, I'm getting SyntaxError: unexpected POST_IF somewhere in this code. Any ideas? -

$('.provider-fields').hide()
  switch parseInt($('#referral_provider_type').val())
    when window.AIDIN.provider_types.hha
      $('.hha-fields').show()
    when window.AIDIN.provider_types.snf
      $('.snf-fields').show()
      $("#length_of_stay").show()
      if ( $("#regular").hasClass('active') )
        $("#search_radius").show()
        if ( $("#search_radius input").val() == '' )
          $("#search_radius input").val window.AIDIN.radii.snf_radius
    when window.AIDIN.provider_types.ltac
      $('.ltac-fields').show()
      if ( $("#regular").hasClass('active') )
        $("#search_radius").show()
        if ( $("#search_radius input").val() == '' )
        $("#search_radius input").val window.AIDIN.radii.ltac_radius
    when window.AIDIN.provider_types.pd
      $('.pd-fields').show()
    when window.AIDIN.provider_types.irf
      $('.irf-fields').show()
      if ( $("#regular").hasClass('active') )
        $("#search_radius").show()
        if ( $("#search_radius input").val() == '' )
        $("#search_radius input").val window.AIDIN.radii.irf_radius

  $('#referral_provider_type').live 'change', (e) ->
    $('.provider-fields').hide()
    $('input[type="checkbox"][name*="referral[referral_care_types_attributes]"]').attr("checked", false)
    switch parseInt($('#referral_provider_type').val())
      when window.AIDIN.provider_types.hha
        $('.hha-fields').show()
      when window.AIDIN.provider_types.snf
        $('.snf-fields').show()
        $("#length_of_stay").show()
        if ( $("#regular").hasClass('active') )
          $("#search_radius").show()
          if ( $("#search_radius input").val() == '' ) 
          $("#search_radius input").val window.AIDIN.radii.snf_radius
      when window.AIDIN.provider_types.ltac
        $('.ltac-fields').show()
        if $( ("#regular").hasClass('active') )
          $("#search_radius").show()
          if ( $("#search_radius input").val() == '' )
          $("#search_radius input").val window.AIDIN.radii.ltac_radius
      when window.AIDIN.provider_types.pd
        $('.pd-fields').show()
      when window.AIDIN.provider_types.irf
        $('.irf-fields').show()
        if ( $("#regular").hasClass('active')   )
          $("#search_radius").show()
          if ( $("#search_radius input").val() == '' )
          $("#search_radius input").val window.AIDIN.radii.irf_radius
2
  • 2
    Rewrite this code? Haven't seen such a mess for a looong time (don't take it personally) Commented Jul 24, 2013 at 17:37
  • You don't need parentheses around the conditions in if statements. Just write if $("#regular").hasClass('active'). Commented Jul 24, 2013 at 17:39

1 Answer 1

2

Indentation problem as shown below:

  switch parseInt($('#referral_provider_type').val())
    when window.AIDIN.provider_types.hha
      $('.hha-fields').show()
    when window.AIDIN.provider_types.snf
      $('.snf-fields').show()
      $("#length_of_stay").show()
      if ( $("#regular").hasClass('active') )
        $("#search_radius").show()
        if ( $("#search_radius input").val() == '' )
          $("#search_radius input").val window.AIDIN.radii.snf_radius
    when window.AIDIN.provider_types.ltac
      $('.ltac-fields').show()
      if ( $("#regular").hasClass('active') )
        $("#search_radius").show()
        if ( $("#search_radius input").val() == '' )
          $("#search_radius input").val window.AIDIN.radii.ltac_radius
    when window.AIDIN.provider_types.pd
      $('.pd-fields').show()
    when window.AIDIN.provider_types.irf
      $('.irf-fields').show()
      if ( $("#regular").hasClass('active') )
        $("#search_radius").show()
        if ( $("#search_radius input").val() == '' )
          $("#search_radius input").val window.AIDIN.radii.irf_radius

  $('#referral_provider_type').live 'change', (e) ->
    $('.provider-fields').hide()
    $('input[type="checkbox"][name*="referral[referral_care_types_attributes]"]').attr("checked", false)
    switch parseInt($('#referral_provider_type').val())
      when window.AIDIN.provider_types.hha
        $('.hha-fields').show()
      when window.AIDIN.provider_types.snf
        $('.snf-fields').show()
        $("#length_of_stay").show()
        if ( $("#regular").hasClass('active') )
          $("#search_radius").show()
          if ( $("#search_radius input").val() == '' ) 
            $("#search_radius input").val window.AIDIN.radii.snf_radius # <----- Here
      when window.AIDIN.provider_types.ltac
        $('.ltac-fields').show()
        if $( ("#regular").hasClass('active') )
          $("#search_radius").show()
          if ( $("#search_radius input").val() == '' )
            $("#search_radius input").val window.AIDIN.radii.ltac_radius # <-------Here
      when window.AIDIN.provider_types.pd
        $('.pd-fields').show()
      when window.AIDIN.provider_types.irf
        $('.irf-fields').show()
        if ( $("#regular").hasClass('active')   )
          $("#search_radius").show()
          if ( $("#search_radius input").val() == '' )
            $("#search_radius input").val window.AIDIN.radii.irf_radius # <---------Here
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.