The function will not be triggered when the form is submitted

I've set up this form to send data to the server-side. It's built in HTML/CSS with AngularJS as well. I made sure that the button is placed inside the form, a common mistake that can cause issues. However, despite my efforts, the function "onAddEditTenantSubmitForm" assigned to the state doesn't seem to trigger when I check it on Chrome at line number 87. Strangely, there are no errors showing up in the console.

If you'd like to take a look at the code snippet, here is the link to JSFiddle: https://jsfiddle.net/jLtsuonx/

''' (function () { var app = angular.module('app'); app.controller('MultiTenantController', ['$scope', '$filter', 'TenantServices', function ($scope, $filter, TenantServices) {

    var uibModal = null;

    var test = "Multi Tenant Controller";

    var state = {
        tenantModel: {
            addedOn: '',
            connectionString: '',
            createdBy: '',
            endOn: '',
            id: '',
            identifier: '',
            isDisabled: '',
            items: [{
                isDisabled: '',
                tenantType: '',
            }],
            name: '',
            startFrom: '',
            tenantType: '',
            userId: '',
        },
    };
    var init = function () {

        $(document).ready(function () {
            tenantTable = $('#table_Tenants').DataTable({
                ajax: {
                    url: 'API/MultiTenant/Pagged',
                    method: 'POST'
                },
                columns: [
                    { data: 'name' },
                    { data: 'identifier' },
                    { data: 'connectionString' },
                    {
                        data: 'startFrom',
                        render: function (startFrom) {
                            return $filter('date')(startFrom, 'medium');
                        }
                    },
                    {
                        data: 'addedOn',
                        render: function (addedOn) {
                            return $filter('date')(addedOn, 'medium');
                        }
                    },
                    {
                        data: 'endOn',
                        render: function (endOn) {
                            return $filter('date')(endOn, 'medium');
                        }
                    },
                    {
                        data: 'actions',
                        orderable: false,
                        render: function () {
                            return `<div class="list-icons">
                                <div class="dropdown">
                                    <a href="#" class="list-icons-item" data-toggle="dropdown">
                                        <i class="icon-menu9"></i>
                                    </a>
                                    <div class="dropdown-menu dropdown-menu-right">
                                        <a href="javascript:void(0)" class="dropdown-item editTenant"><i class="icon-database-edit2"></i>Edit</a>
                                        <a href="javascript:void(0)" class="dropdown-item deleteTenant"><i class="icon-database-remove"></i>Delete</a>                                                                                                                                                                                                                                                                                                                   
                                    </div>
                                </div>
                            </div>`;
                        }
                    }
                ]
            });

            tenantTable.on('click', '.deleteTenant', function () {
                const $row = $(this).closest('tr');
                const rowData = tenantTable.row($row).data();
                deleteTenant(rowData);
            });
        })
    };

    const onAddEditTenantSubmitForm = function (newTenatForm) {
        if (!state.tenantModel.userId) {
            addTenant(newTenatForm);
        }
        else {
            //updateUser(newUserForm);
        }
    };

    var addTenant = function (newTenatForm) {
        state.isLoading = true;
        TenantServices.addTenant(state.tenantModel).then(
            function () {
                swalInit.fire({
                    title: 'Success',
                    text: 'Tenant has been created',
                    type: 'success'
                });
                userTable.ajax.reload();
                closeModal();
            },
            function (errorResponse) {
                if (errorResponse.status === 400 && errorResponse.data.duplicateRecord) {

                }
                else if (errorResponse.status === 500) {
                    swalInit.fire({
                        title: 'Server Error',
                        text: 'An server error occurred while adding tenant.',
                        type: 'error'
                    });
                }
            }
        )
            .finally(() => state.isLoading = false);
    };  

    var deleteTenant = function (rowObj) {
        state.isLoading = true;
        TenantServices.deleteTenant(rowObj.id).then(
            function () {
                swalInit.fire({
                    title: 'Success',
                    text: 'Tenant Deleted!',
                    type: 'success'
                });
                tenantTable.ajax.reload();
                closeModal();
            },
            function (errorResponse) {
                if (errorResponse.status === 500) {
                    swalInit.fire({
                        title: 'Server Error',
                        text: 'An server error occurred while Deleting Tenant.',
                        type: 'error'
                    });
                }
                else if (errorResponse.status === 404) {
                    swalInit.fire({
                        title: 'Server Error',
                        text: 'Tenant not found on Server.',
                        type: 'error'
                    });
                }
            }
        )
            .finally(() => state.isLoading = false);
    };

    var closeModal = function () {
        if (uibModal) {
            uibModal.close();
        }
    };

    state.onAddEditTenantSubmitForm = onAddEditTenantSubmitForm;
    state.test = test;

    $scope.state = state;
    $scope.init = init;

}]);

})(); '''

Answer №1

Make sure that the function being called in the template through ng-submit is within your scope and update the template to call it correctly.

In your controller, change your function from a const and bind it to the scope.

$scope.onAddEditTenantSubmitForm = function (newTenatForm) {

In your template, add "$ctrl." before your function name.

 ng-submit="$ctrl.onAddEditTenantSubmitForm(newTenatForm)"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Remove a data entry from the MySQL database by selecting the corresponding row in the table and utilizing the DELETE function

Is there a way to remove a record from my MySQL database by clicking on a row in a table that is generated using ejs? Below is the code I am currently using to generate the table rows. <% res.forEach(function(item){ %> <tr> ...

Retrieve childNodes of the Select All input using jQuery from the container node with the class name "container"

I am trying to retrieve the text value of all the childNodes within the container of the corresponding input when the Select All checkbox is checked. Currently, my code captures the text inside each input label. However, it only logs the label (e.g. &apos ...

Ways to conditionally display a component in Next.js without the issue of caching CSS styles

I'm a newcomer to Next.js and I'm still trying to wrap my head around how the caching works. Let's take a look at this simplified example: An index page that displays either Test1 or Test2 components, based on whether the current minute is ...

Should the button be eliminated in favor of simply requesting input from the user?

Looking for help with my code. How can I set it up so that when the HTML file is clicked on, it prompts for input instead of displaying a button? I'm new to coding and could use some guidance. <!doctype html> <html> <head> <meta ...

Callbacks in Laika tests go untriggered

Meteor.collection.insert() allows for the use of a callback as one of its arguments. To demonstrate, you can start a new Meteor project and execute the following code in the browser's console. my_collection = new Meteor.Collection("myCollection"); my ...

Decide on the javascript/jquery libraries you want to include

My app is experiencing slow loading times on the home screen and students using it from school district computers are running into ERR_CONNECTION_RESET errors due to strict firewalls. The excessive loading of javascript and jquery libraries in the head of ...

The child element fails to increase in size if the parent element has a minimum height specified

I'm having trouble getting min-height to work properly. The issue is that my child element doesn't inherit the height of its parent, so it's not setting its own height correctly. How can I resolve this? #middle_Wrapper { width: 100%; mi ...

Leveraging the power of dual CSS classes for a single element

Can you help me troubleshoot this? I have a .social div, and I want zero padding on the top for the first one, and no bottom border for the second one. I tried creating classes for the first and last scenarios, but it seems like something is off: .socia ...

What causes the return of 'undefined' during the execution of type coercion?

Can you explain why the type of a variable changes but the value remains undefined when trying to set it? let average; // Do I need to initialize with 'average = 0;' for it to work properly? for (const [oddName, odd] of Object.entries(game.odd ...

Why does my Javascript cross-domain web request keep failing with a Status=0 error code?

UPDATE: I've been informed that this method doesn't work because craigslist doesn't have an Allow-Cross-Domain header set. Fair point. Is there an alternative way to download a page cross-domain using Javascript in Firefox? It's worth ...

To validate any object, ensure that it contains a specific key before retrieving the corresponding value in typescript

When looking at a random object, my goal is to verify that it follows a certain structure. obj = {WHERE:{antherObject},OPTIONS{anotherObject}} Once I confirm the object has the key using hasProperty(key), how can I retrieve the value of the key? I thoug ...

"Converting an angular date-picker into a popup-date-picker: A step-by-step

I am currently working on a project in Plunker and I would like to implement an Angular date-picker-popup similar to the one in my design. Any suggestions or ideas on how to achieve this? Thank you in advance! ...

The ng-controller directive is not functioning accurately

I attempted to execute the following basic HTML: <!DOCTYPE html> <html ng-app="tempApp"> <head> <script src="js_libs/angular/angular.min.js"></script> <script src="js_libs/angular/bootstrap.js"></script&g ...

Rotation to a point in a circle using three.js

Currently, I am in possession of 2 instances of THREE.Vector3(). My task at hand is to create a circular shape around one vector with the second vector serving as a tangent. I have determined the radius of the circle geometry based on the distance betwee ...

Ways to implement varying services based on route parameters

Imagine having two services with similar APIs but different implementations. myApp.module('myModuleApp').service('BananaService', function() { this.name = 'banana'; }); myApp.module('myModuleApp').service(&apo ...

Is there a way to determine in FireBug the specific JavaScript code being received from the server following an Ajax request?

Within my HTML code, I am transmitting a dollar amount to the server in order to convert its currency within the application. Is there a way for me to use FireBug to track and view the JavaScript that is being received from the server following this Ajax ...

Dealing with bulkWrites in Mongoose and MongoDB: how to handle cast errors with finesse

When importing data into my app's database using MongoDB's bulkWrite operation, I encounter a challenge. The data may contain errors as it comes from an external source. To maintain the integrity of my data, I need to update my collection while s ...

Utilize INTERFACE-driven capabilities in ReactJS to dynamically render components based on a variable

How can interface-based functionality be used to render components based on tab selection? If we have 3 components as follows: OneTimeOnlyScheduleComponent DailyScheduleComponent WeeklyScheduleComponent We aim to have all of these components implement t ...

Issue with JavaScript function loading website homepage solely is functioning only for the first time

I am in the process of creating my own personal website. To ensure seamless navigation, I added a "home" button that, when clicked, triggers a JavaScript function called loadhomepage() to load the homepage. While this function works perfectly upon initial ...

What steps can be taken to ensure your bot successfully sends the second argument?

Who just handed out an L to user#0000? Looks like JohnGameRage#0000 did! ...