This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jfo
jfo

Hi,

I read all examples in the docs here: https://octobercms.com/docs/cms/ajax#javascript-api But the documentation doesn't mention where to put the Javascript code.

What I am trying to achieve is:

  • user clicks delete button
  • before the confirmation message is displayed I would like to call a javascript function to ask the user to enter a reason why the record is being deleted.
  • the reason would them be submitted to the controller to be used on the beforeDelete event.

I put the code below on my controller update.htm file, but it's not being invoked:

{% put scripts %}
    <script type="text/javascript">
        $(document).ready(function() {
            $('form').request('onDelete', {
                var reason = prompt("Why are you deleting this record?"),
                data: { deleteReason: reason }
            })
        });
    </script>
{% endput %}

Where should I put a code that could call a custom javascript on a backend form event?

daftspunky
daftspunky

Try this

<button onclick="onDeleteWithReason()">Delete</button>

<script type="text/javascript">
    function onDeleteWithReason() {
        var reason = prompt('Why are you deleting this record?')
        if (reason) {
            $('form').request('onDelete', {
                data: { deleteReason: reason }
            })
        }
    }
</script>

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.