S
S
Sergey2015-09-17 11:10:28
Angular
Sergey, 2015-09-17 11:10:28

Why is the data not being submitted in the form?

Making a multi-window form

<form ng-submit="form.processForm()" name="form.formData" novalidate>    
      <h1>Sign Up</h1>
            <div ui-view></div>
  </form>

registration. In the first step, the user is simply asked whether he is a user or a company. If "company" is selected, a check is made in the controller and a modal window opens with an additional choice "form.formData.group2. After choosing in it, redirection to the next state occurs with the completion of registration.
Question - the data "form.formData.group2in form.formData does not get. Why?
The modal window is opened with
vm.showModal = function(ev) {
    $mdDialog.show({
                templateUrl: 'dialog.html',
                parent: angular.element(document.body),
                targetEvent: ev,
                     controller: function DialogController($mdDialog) {
                       var vm = this;
                    vm.closeDialog = function() {
                        $mdDialog.hide();
                        $state.go("form.credential");
                    };
                },
                controllerAs: 'dc'
          });
  }
in the window
<md-dialog>
     <div layout="row" layout-align="start start">
        <md-radio-group ng-model="form.formData.group2">
            <md-radio-button value="resident">Resident</md-radio-button>
            <md-radio-button value="nonresident">Non resident</md-radio-button>
        </md-radio-group>
       
       <a class="md-button" ng-click="dc.closeDialog()">Next</a> 
      
    </div>
    </md-dialog>

Only enters the console
$submitted: true
$valid: true
address: "Mars"
group1: "company"
password: "123456"
username: "[email protected]"

Yes, and the output to the console is not just form.formData, but like this:
Object {$$parentForm: Object, $error: Object, $$success: Object, $pending: undefined, $name: "form.formData"…}

Could this be because closing the dialog resets the received values?
Plnkr

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Dunayevsky, 2015-09-17
@TsarS

1. Display the ability to select the type of organization right in the same form where the user selects whether he is an individual or an organization. ng-if to the rescue.
2. You should not call the dialog box, and if you do, make a cancel button.
3. In the Angular Material dialogs, your $scope. For proper processing, use the following code:

$mdDialog.show({
    templateUrl: '/template/dialog.html',
    controller: [ '$scope', '$mdDialog', function($scope, $mdDialog){
        $scope.cancel = $mdDialog.cancel; // Отмена. Ничего сложного.
        $scope.save = function(){
            $mdDialog.hide($scope.model); // Диалог закрывается, promise разрешается моделью
        };
    }]
}).then(function (model) {
    // Та самая модель, которую возвращает $mdDialog. 
    // При использовании метода cancel() выполняет код для reject
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question