0

I have the following coffeescript:

  $("#complete").click ->
    bootbox.dialog "Remember, if you complete the workorder you won't be able to add labor and materials.", [
      label: "Complete"
      class: "btn-success"
      callback: ->
        $("td").filter(':contains("ID:")').each ->
          woid = $(this).nextAll().text()
        $.update "/workorders/" + woid,
         workorder:
           wostatus_id: 232
    ,
     label: "Cancel"
      class: "btn-danger"
      callback: ->
        return 'false'
    ]

When it runs, I get this in the browser console:

Uncaught ReferenceError: woid is not defined 

Thanks for the help!

1 Answer 1

1

Variables are scoped to the function where you first assign to them. To make woid available, initialize it to null outside your filter callback:

    woid = null

    $("td").filter(':contains("ID:")').each ->
      woid = $(this).nextAll().text()
    $.update "/workorders/" + woid,
     workorder:
       wostatus_id: 232

And as always, check your compiled JavaScript when debugging. The answer will usually be quite obvious.

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.