Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoffeeScript - Unmatched OUTDENT

I've been trying to pass my working javascript code into CoffeeScript but i can't get pass this error:

unmatched OUTDENT on line 55

This is the coffeescript code

$(document).on("click",".save_button", ->
    $form = $(this).parent().parent().parent().parent().parent().parent()
    $form.bind("ajax:complete", ->
                $actionURI = $form.attr("action");
        $.get(window.location.protocol+"//"+window.location.host+$actionURI+".js",(data) ->
                    $form.parent().parent().prev().html(data); //Line 55
                    closeSaveElement()
        ,"html")
    );
    $form.submit();   
    return false;
);

i've tried putting and erasing ; everywhere but i don't whats wrong. I also tried to change -> for => but the same error pops up.

like image 873
KoU_warch Avatar asked Mar 24 '26 08:03

KoU_warch


1 Answers

Valid JS isn't really valid CoffeeScript. You'd have to do something like this:

$(document).on "click", ".save_button", ->
    $form = $(this).parent().parent().parent().parent().parent().parent()

    $form.bind "ajax:complete", ->
        $actionURI = $form.attr "action"
        $.ajax
            type: "get"
            url: "#{window.location.protocol}//#{window.location.host}#{$actionURI}.js"
            dataType: "html"
            success: ->
                $form.parent().parent().prev().html(data)
                closeSaveElement()

    $form.submit()

    return false

Also, do something about this line:

$form = $(this).parent().parent().parent().parent().parent().parent()

.closest() should be helpful.

like image 85
Blender Avatar answered Mar 25 '26 22:03

Blender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!