Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

When I click "Cancel" in modal window, checkbox is unchecked, but it has to be checked (scope.enabledLogin has true after "Cancel" button is pressed and modal window is dismissed). Why?

Jade:

.checkbox(ng-show="showEnabledLogin", ng-class="{'disabled': (!email.length || userForm.email.$error.email)}")
      label(for="enabledLogin")
        input(ng-show="showEnabledLogin", type="checkbox", id="enabledLogin", name="enabledLogin", ng-model="enabledLogin", ng-disabled="(!email.length || userForm.email.$error.email)", ng-change="showEnabledLoginModal()")
        span Player login enabled

JS:

scope.isEnabledLoginManuallyUnchecked = false;
function checkIfEnabledLoginManuallyUnchecked() {
        if(scope.isEnabledLoginManuallyUnchecked) {
          scope.showEnabledLogin = false;
          scope.showInviteLogin = true;
          scope.enabledLogin = false;
        } else {
          scope.showEnabledLogin = true;
          scope.showInviteLogin = false;
          scope.enabledLogin = true;
        }
      }
var enabledLoginModal,
                modalScope;

      var isOpened = false;

      scope.showEnabledLoginModal = function () {
        if (isOpened) return;
        if ((scope.email.length || scope.userForm.email.$error.email)) {
          if (scope.enabledLogin) {
              debugger;
            var child = scope.$new();
            var extension = {
              cancel: function (e) {
                scope.isEnabledLoginManuallyUnchecked = false;
                checkIfEnabledLoginManuallyUnchecked();
                enabledLoginModal.dismiss(e);
                isOpened = false;
              },
              modal: {
                title: 'Please confirm'
              }
            };
            modalScope = angular.extend(child, extension);
            var modalOptions = {backdrop: 'static', templateUrl: 'app/player/edit/show-enabled-login-modal.html'};
            enabledLoginModal = Modal.custom(modalOptions, modalScope, 'modal-danger');
            isOpened = true;
            enabledLoginModal.result.then(function (result) {
            });
          }
        }
      }
share|improve this question
    
its better to create a fiddle so it will be easy to fix – gayathri Jun 9 at 8:35

Please find this in your above code and there

 cancel: function (e) {
                scope.isEnabledLoginManuallyUnchecked = false;
                checkIfEnabledLoginManuallyUnchecked();
                enabledLoginModal.dismiss(e);
                isOpened = false;
              },

This will execute once your click on the modal's cancel button and then you set

scope.isEnabledLoginManuallyUnchecked = false;

that is reason it i will get unchecked also

because you called

enabledLoginModal.dismiss(e);
                isOpened = false;

these lines your modal closing when you click on cancel . if I am not clear please create fiddle so can research more.

khajaamin

share|improve this answer
    
According to this code, when scope.isEnabledLoginManuallyUnchecked = false, then scope.enabledLogin = true: function checkIfEnabledLoginManuallyUnchecked() { if(scope.isEnabledLoginManuallyUnchecked) { scope.showEnabledLogin = false; scope.showInviteLogin = true; scope.enabledLogin = false; } else { scope.showEnabledLogin = true; scope.showInviteLogin = false; scope.enabledLogin = true; } } – max Jun 9 at 8:59
    
Guys, thank for your efforts, it was issues with scope. I used scope.object.field instead of scope.field and all works now :) – max Jun 12 at 6:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.