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

The issue with NGX-Bootstrap/Angular Pagination arises when attempting to adjust the maxSize input while the screen view (width) is being altered

Currently, I am utilizing the Pagination component from Valor Software (click here to access). I am interested in adjusting the maxSize input dynamically based on changes in screen width. For reference, please see this example: Click to view example. It ...

Avoid displaying duplicate items from the array

Utilizing react js, I am attempting to iterate through an array of objects and display the name of each object in the array: const arr = [ { name:"Bill", age:88 }, { name:"Bill", age:18 }, { name:"Jack", age:55 }, ] ...

Ways to evenly distribute children in a row using CSS

https://i.stack.imgur.com/HmziN.png The image above showcases the desired effect I am aiming for. It is important to note that the width of the container div may vary. The child elements should have consistent spacing between each other as well as the le ...

Adding li elements dynamically, how can we now dynamically remove them using hyperlinks?

Please refrain from using jQuery code, as my main focus is on learning javascript. I am currently experimenting with adding li items dynamically to a ul when a button on the HTML page is clicked. Here's a sample implementation: HTML: <ul id="myL ...

discord.js: Bot keeps sending duplicate embeds

I recently set up my discord bot to respond with a message when I enter a specific command, but I've run into an issue where it's sending the same embed twice. I've tried troubleshooting, but so far I haven't been able to pinpoint the c ...

"When using Webpack and Sass, the background image specified with background: url() is processed correctly. However, when using webpack-dev-server, the image is

Currently, I am utilizing Webpack 2 in conjunction with webpack-dev-server and Sass loader. Here is my current configuration: { test: /\.scss/, loaders: [ "style", { loader: "css", query: { modules: false, sourceMap: true } }, ...

Move to the top of the page when the next action is activated

I am working with an Angular 8 application. Within the application, I have implemented navigation buttons for next and previous actions. My goal is to ensure that when a user clicks on the "next" button, the subsequent page starts at the top of the page ...

Hide the cursor when the text box is in focus

Is there a way to remove the cursor from a textbox when it is clicked on? I want the cursor to disappear after clicking on the textbox. jQuery(document).ready(function($) { $(function(){ $('#edit-field-date-value-value-datepicker-popup-0&ap ...

Utilizing jQuery to incorporate a radio input function in a POST request

When the Index.php page button is pressed, data is sent to the Resultx.php script page, which then responds with an asynchronous call back on the same Index.php page. index.php <script> $(document).ready(function() { $("#input_form").subm ...

The functionality of the webservice is not functioning properly

I'm currently working with Express and NodeJS to create a simple hello world webservice. I am attempting to call this webservice in ReactJS using Axios, but I am encountering issues with the response from the webservice. Below is my code for the webse ...

Is there a way to transfer parameters from a Vue function to a component?

I am struggling to find the right solution for passing parameters to a function. I need to use NavigateTo to send a String value to my index in order to switch components without using Vue Router. Home.js Vue.component('Home', { props: [&apo ...

Converting an HTML form with empty values into JSON using JavaScript and formatting it

While searching for an answer to my question, I noticed that similar questions have been asked before but none provided the solution I need. My situation involves a basic form with a submit button. <form id="myForm" class="vertically-centered"> ...

Issues with Angular Material Pagination functionality may be causing unexpected behavior

I'm facing an issue with displaying data in an HTML table using an API. I've tried to implement pagination to show 3 or 6 rows per page, but it's not working as expected. Currently, all the data is being displayed without any pagination, whe ...

"Enhance Your Slide Up/Down Menu with a Unique Hover Effect in jQuery

HTML: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="navigation_desktop"> <div class="button_desktop_01">1.0 Main Menu <div class="SlideItem ...

Encountering an error while trying to execute `$(document).ready(function() {}

Recently, I delved into the world of JavaScript, particularly Jquery. As I encountered the $(document).ready(function() {}); statement and added it to my code, I faced an issue when placing it within the header tag of my HTML. The script tag would display ...

Deactivating a form field depending on a selected radio button in Angular 2

If I have two radio buttons, with a click function called localClick for the first button to give value 1 and the second button to give value 2. <div class="ui-g-12"><p-radioButton name="group1" value="Local" (click)=localClick(1) label="Local"&g ...

Problems with installing ambient typings

I'm having trouble installing some ambient typings on my machine. After upgrading node, it seems like the typings are no longer being found in the dt location. Here is the error message I am encountering: ~/w/r/c/src (master ⚡☡) typings search mo ...

Issues with jQuery .click and .html functions not functioning as expected

Does anyone have experience creating a game with jQuery? I can't seem to get the options after the first choice to work. Sorry, I don't have a working example at the moment. --- jQuery --- $(document).ready(function() { $(".console"). ...

Unsure how to proceed with resolving lint errors that are causing changes in the code

Updated. I made changes to the code but I am still encountering the following error: Error Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. It is recom ...

Maximizing JavaScript efficiency: Returning a value within an if statement in an AJAX call

In my function, I have a condition that checks the idType. If it is 1, an ajax call is made to a php file to retrieve the name associated with the specific idName and return it. Otherwise, another example value is returned. function obtainName(idName, idTy ...