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

Custom validation with popup confirmation before adding an appointment

I need to do a validation outside of the typical ones built into the scheduler's editor. I've tried setting it inside the onActionBegin and onActionComplete to fire before allowing the event to actually finish with no luck.

How can I intercept the onActionBegin/onActionComplete events before the scheduler actually attempts to save the appointment? Also, is there a way to customize the editor's save button so it doesn't automatically save before this custom validation I have?

7 Replies

KK Karthigeyan Krishnamurthi Syncfusion Team August 1, 2019 09:18 AM UTC

Hi Robert 
 
Syncfusion greetings. 
 
By default, Scheduler supports validation on save button click and kindly refer the below links. 
 
Alternatively validation can be performed using actionBegin and actionComplete events. In the below sample, when a save button is clicked without value in Title field, editor will not close and alert will be displayed. 
 
onActionBegin(args: ActionEventArgs): void { 
    if (args.requestType === "eventCreate" && args.data[0].Subject === "Add title" && !isNullOrUndefined(document.querySelector('.e-schedule-dialog'))) { 
      this.scheduleObj.uiStateValues.isBlock = true; 
      args.cancel = true; 
      alert('Enter Title'); 
    } 
  } 
  onActionComplete(args: ActionEventArgs): void { 
    if (!isNullOrUndefined(document.querySelector('.e-schedule-dialog'))) { 
      let diaObj = (document.querySelector('.e-schedule-dialog') as EJ2Instance).ej2_instances[0] as any; 
      this.scheduleObj.uiStateValues.isBlock = false; 
      diaObj.hide(); 
    } 
  } 
 
Regards, 
Karthi 
 



OE Ola Ekdahl April 20, 2020 05:12 PM UTC

Hi Karthi,
I'm trying to do the same thing but I don't think your Stackblitz example is working as described. The editor window is still closing before the alert is shown. Is there a way to keep the the Editor open until validation in on ActionBegin is done?


VM Vengatesh Maniraj Syncfusion Team April 21, 2020 06:22 AM UTC

Hi Ola Ekdahl, 

Greetings from Syncfusion Support. 

We have checked our sample which is provided in the last update and the sample is to validate the field from the editor window. And also we have checked your reported problem with that sample and we suspect that your requirement is to validate the field from the quick popup and keep open the window after close the alert. So we have achieved your requirement by making use of popupClose event. This event will help us to validate the fields before saving and keep opening.  

onPopupClose(args): void { 
    if (args.type === "QuickInfo" && (this.scheduleObj.quickPopup as any).isCrudAction && (args.data as any).Subject === "Add title") { 
      args.cancel = true; 
      alert('Enter Title'); 
    } 
    if (args.type === "Editor" && (this.scheduleObj.eventWindow as any).isCrudAction && (args.data as any).Subject === "Add title") { 
      args.cancel = true; 
      alert('Enter Title'); 
    } 
  } 


Kindly check the above sample and get back to us if you need any further assistance. 

Note: Kindly use our latest packages to get the popupClose event 

Regards, 
Vengatesh 



WZ WEIMIN ZHANG replied to Vengatesh Maniraj March 22, 2022 01:13 PM UTC

hi Vengatesh


I'm facing the same problem like this question. But I have to send a post request to the backend first , to get the DB data for checking is the input in the pop-window already existed or not . It seems ,the code "args.cancel=true" can not work well if I put it after await.this.http.post....in a async onPopupClose method .I want know if you have any idea about this problem.

thanks



VM Vengatesh Maniraj Syncfusion Team March 28, 2022 11:11 AM UTC

Please refer to the below sample where we have done this by making use of the popupOpen and popupClose events.

https://stackblitz.com/edit/angular-7gxfnm-ukxvoa?file=app.component.ts



WZ WEIMIN ZHANG replied to Vengatesh Maniraj March 30, 2022 04:36 AM UTC

Thanks a lot.I get your point.By the way, is there any possible by make uses of onActionComplete method? It seems,Once I enter the onActionComplete method.The popup window will must be trun off.Am I right?



VM Vengatesh Maniraj Syncfusion Team April 1, 2022 10:30 AM UTC

Yes WEIMIN. Once you enter the onACtionComplete method, the popup will be turned off. Since the added/updated data will be saved in the database before entering the onActionComplete, this is not possible to validate the data in the onActionComplete method. So we recommend you use the popupClose method to perform better data validation.


Loader.
Up arrow icon