3

I want to give a confirm to the screen before deleting the object, but the return statement is constantly being underlined.How can I fix that?

{% if notifications %}
{% for not in notifications %}
        <li>
            <figure><img src="{{not.object.image.url}}" alt=""></figure>
            <small>{{not.object.category.name}}</small>
            <h4>{{not.object.title}}</h4>
            <p>{{not.message}}</p>
            <!-- <p><a href="#0" class="btn_1 gray"><i class="fa fa-fw fa-eye"></i> View course</a></p> -->
            <ul class="buttons">
                <li><a onclick="return confirm('Are you sure?');"  href="{% url 'deleteNotificationsAdmin' not.pk %}" class="btn_1 gray delete wishlist_close" >
                    <i class="fa fa-fw fa-times-circle-o"></i> Delete</a></li>
            </ul>
        </li>
{% endfor %}
{% endif %}

When I hover over it with the mouse it gives an error

A 'return' statement can only be used within a function body.

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100

1 Answers1

5

So it turns out A 'return' statement can only be used within a function body. error is actually a bug in Visual Studio Code and currently scheduled to be fixed in March 2022 Milestone.

And according to HTML 5.2: 7.4, it is valid to use return value with event handlers.

Process return value as follows:

  • If the event type is mouseover

  • If the event type is error and E is an ErrorEvent object

    • If return value is a Web IDL boolean true value, then cancel the event.
  • If the event type is beforeunload

    • NOTE: The event handler IDL attribute’s type is OnBeforeUnloadEventHandler, and the return value will therefore have been coerced into either the value null or a DOMString.

    • If the return value is null, then cancel the event.

    • Otherwise, if the Event object E is a BeforeUnloadEvent object, and the Event object E’s returnValue attribute’s value is the empty string, then set the returnValue attribute’s value to return value.

  • Otherwise If return value is a Web IDL boolean false value, then cancel the event.

As a workaround, you can disable html.validate.scripts option from Visual Studio Code settings.

Ali Demirci
  • 5,302
  • 7
  • 39
  • 66