We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Angular : prevent Closing the Edit Window issue

Hi every one,
I'm tring to cancel the colsing of the Edit Window but having some trouble.

here is my code :
HTML File
<ejs-schedule #scheduleObj
(actionBegin)="onActionBegin($event)"
(dataBound)="onDataBound()"></ejs-schedule>

TS File
cancel : boolean = false;
@ViewChild("scheduleObj")
scheduleObj: ScheduleComponent;
onActionBegin(args: ActionEventArgs): void {
var data = (args.requestType === 'eventCreate') ? args.data[0] : (args.data);
if(data && (data.StartTime>data.EndTime))
{
args.cancel = true;
this.cancel = true;
}
}

onDataBound() {
this.scheduleObj.eventWindow.dialogObject.beforeClose = function (args) {
console.log(this.cancel);//Here cancel is undefined!!!!! why???
args.cancel = this.cancel;//if I replace by true, It works perfectly
this.cancel = false;
}
}

Thanks in advance for help.

JMEL.

7 Replies

NR Nevitha Ravi Syncfusion Team April 24, 2019 07:15 AM UTC

Hi JMEL Becha, 

Greetings from Syncfusion Support. 

We have prepared a sample to prevent the closing of editor window if the subject of the event is New for your reference which can be viewed from the following link.  In the shared code, this.cancel is undefined as here dialog instance is available in ‘this’. So we have stored it in separate variable in actionBegin and assign that variable in beforeClose event. 

onActionBegin(args: ActionEventArgs): void { 
    if (args.requestType === 'eventCreate' || args.requestType === 'eventChange') { 
      var subject = (args.requestType === 'eventCreate') ? args.data[0].Subject : (args.data as any).Subject; 
      if (subject == 'New') { 
        args.cancel = true; 
        this.cancel = true; 
        let val = this.cancel; 
        this.scheduleObj.eventWindow.dialogObject.beforeClose = function (args) { 
          args.cancel = val; 
          alert("Don't Close the Appointment Window"); 
        } 
        this.cancel = false; 
      } 
    } 
  } 

Please try the sample at you end and let us know if you need any further assistance. 

Regards, 
Nevitha. 



JB JMEL Becha April 24, 2019 10:14 AM UTC

Great !!
It Works perfectly.

Thanks a lot.

JMEL.


NR Nevitha Ravi Syncfusion Team April 24, 2019 12:59 PM UTC

Hi JMEL, 
  
Thanks for your update. 
  
We are glad that your requirement has been fulfilled. 
  
Regards, 
Nevitha 



PK Parthkumar Kakadiya January 21, 2020 04:08 PM UTC

Hi,

In this solution I am getting strange problem.

If i give subject 'New' at first time, I am getting alert with the message. which is correct .