                 properties: label: newLabel, isHtml: isChecked.toString()
             labelEditor().container.hide()
             # Update values in the DOM, without waiting for the server to send us the value
-            currentControl.find('.xforms-label').text(newLabel)
+            currentLabel.text(newLabel)
             setLabelHtml(isChecked)
 
     # Heuristic to close the editor based on click and focus events


    # Show editor on click on label
    startEdit = ({target}) ->
        label = $(target)
        # We don't want the browser to set the focus on the input
        label.removeAttr('for')
        # Remember which control we're editing
        currentControl = label.parent('.xforms-control')
        # Position and populate editor
        labelEditor().container.show()
        labelEditor().container.offset(label.offset())
        labelEditor().textfield.outerWidth(label.outerWidth() - labelEditor().checkbox.outerWidth(true))
        labelEditor().textfield.val(label.text()).focus()
        labelEditor().checkbox.prop('checked', isLabelHtml())

    $('.fb-main').on('click', '.xforms-label', startEdit)

    OD = ORBEON.xforms.Document

    currentControl = null
    currentLabel = null
    isLabelHtml = -> currentControl.is('.fb-label-is-html')
    setLabelHtml = (isHtml) -> currentControl.toggleClass('.fb-label-is-html', isHtml)

