0

I can't get the name of a form which is in ngDialog. My dialog is:

$scope.dialogAddNewParent = ngDialog.open({
                template: 'addNewParentDialog',
                className: 'ngdialog-theme-default dialogwidth550',
                scope: $scope
            });

The problem is that in ngDialog I have a from with name="addNewParentForm", but when I'm trying to validate this form to my controller, i can't get the name of my form,so i get this error.

Cannot read property 'lastName' of undefined 

lastName is the name of an input of my form.

in my html i have this script for the dialog:

<script type="text/ng-template" id="addNewParentDialog">
    <div class="p-lg" style="color:#748690">ADD NEW PARENT</div>
    <form name="addNewParentForm" ng-submit="addNewParent(addNewParentForm.$valid)" novalidate class="form-validate form-horizontal p-lg">
        <div class="form-group">
            <label style="color:#1a9fc8" class="col-sm-3 control-label">Last Name*</label>
            <div class="col-sm-9">
                <input type="text" name="lastName" ng-model="new_parent.lastName" required="" ng-maxlength=80 class="form-control" value="{{new_parent.lastName}}" />
                <span ng-show="addNewParentForm.lastName.$dirty &amp;&amp; addNewParentForm.lastName.$error.required" class="text-danger">This field is required</span>
                <span ng-show="addNewParentForm.lastName.$dirty &amp;&amp; addNewParentForm.lastName.$error.maxlength" class="text-danger">Input cannot be longer than 80 characters</span>
            </div>
        </div>
        <div class="form-group">
            <label style="color:#1a9fc8" class="col-sm-3 control-label">First Name*</label>
            <div class="col-sm-9">
                <input type="text" name="firstName" ng-model="new_parent.firstName" required="" ng-maxlength=80 class="form-control" value="{{new_parent.firstName}}" />
                <span ng-show="addNewParentForm.firstName.$dirty &amp;&amp; addNewParentForm.firstName.$error.required" class="text-danger">This field is required</span>
                <span ng-show="addNewParentForm.firstName.$dirty &amp;&amp; addNewParentForm.firstName.$error.maxlength" class="text-danger">Input cannot be longer than 80 characters</span>

            </div>
        </div>.......

and in my controller

....$scope.addParent = function (choice) {
    switch (choice) {
        case 1:
            $scope.dialogAddNewParent = ngDialog.open({
                template: 'addNewParentDialog',
                className: 'ngdialog-theme-default dialogwidth550',
                scope: $scope
            });
            break;
        case 2:
            $scope.dialogAddNewParentFromList = ngDialog.open({ template: 'addNewParentFromListDialog', controller: 'StudentEditController', className: 'ngdialog-theme-default dialogwidth350 ngdialog-overlay', overlay: false, scope: $scope, data: {} });
            break;
    }
}
$scope.addNewParent = function (valid) {
    $scope.submitted = true;
    var input = $scope.addNewParentForm;
    if (valid) {
        $scope.dialogAddNewParent.close();
        $scope.parents.push($scope.new_parent);
        console.log('Parents', $scope.parents)
    } else {
        console.log('Not valid!!');
        $scope.addNewParentForm.lastName.$dirty = true;//here is the problem with undefined

    }
};.....

Thanks!

Steven Lignos
  • 217
  • 3
  • 10

0 Answers0