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

Toast - Error or Success

Hi expert,

I cannot find the example - source codes on Syncfusion so I am wondering if it is possible to toggle by displaying "Error" or "Success" (toast) by clicking "Submit button".

Let's say if I have form validator and try to click Submit, it will display error messages (Toast). If all values are not empty, it will show success.

However for my case, it shows two toast like Error then Success. I am wondering if I can only show success instead of error? I try to hide error toast but it will hide 1 second then success toast appear. I don't like it. Any advice?

What am I missing?

public toastObj: ToastComponent; --> it should show either success or error

public toasts: { [key: string]: Object }[] = [
{ cssClass: 'e-toast-success', icon: 'e-success toast-icons', title: 'Success', content: 'Success.' }
        { cssClass: 'e-toast-danger', icon: 'e-error toast-icons', title: 'Error', content: 'Error.' }
];

// if all values are clear, it will show success message
private handleOnSubmit = (values: VeMaContract) => {
     document.getElementById("hideToast").style.display = 'none'; // hide error toast but not working
     this.toastObj.show(this.toasts[0]);
     this.props.saveContract(values); // save contract
};

// this is submit button --> it will always display error toast
private handleOnValidation = () => {
this.toastObj.show(this.toasts[0]);
};
private onclose(e: ToastCloseArgs): void {
const btnEleHide: HTMLElement = document.getElementById('hideToast');
(e.toastContainer.childElementCount === 0) ? btnEleHide.style.display = 'none' : btnEleHide.style.display = 'inline-block';
};

private onbeforeOpen(): void {
const btnEleHide: HTMLElement = document.getElementById('hideToast');
btnEleHide.style.display = 'inline-block';
};

3 Replies

CI Christopher Issac Sunder K Syncfusion Team October 31, 2018 05:45 PM UTC

Hi DeBao Chua, 
 
Thank you for contacting Syncfusion support. 
 
We have validated this scenario and as per the Toast control behavior, it is just created on the page and only a show and hide is required to make it display or not display. So we have to show and hide this based on our use case only.  At initially we can hide this toast globally on before every action and then show or hide it. 


  contactSubmit(e) { 
    e.preventDefault(); 
    this.toastObj.hide("All"); 
    if (this.handleValidation()) { 
      this.toastObj.show(this.toasts[0]); 
    } else { 
      this.toastObj.show(this.toasts[1]); 
    } 
 
  } 
 



Please check the demo sample and let us know if you have further queries. 

Thanks,
Christo



DC DeBao Chua October 31, 2018 05:50 PM UTC

Hi Christo,

Thanks for the source codes and explaination about Toast component. I get the picture clearly. :)

Yes it looks great - works perfectly. Thank you!


DL Deepa Loganathan Syncfusion Team November 1, 2018 11:31 AM UTC

Hi DeBao, 
 
 
Most welcome. Please let us know if you have any further queries. 
 
 
Regards,  
 
Deepa L. 


Loader.
Live Chat Icon For mobile
Up arrow icon