Developer forum

Forum » Development » Display alert or error from Notification Subscriber

Display alert or error from Notification Subscriber

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I am using a notification to control the validation of the EAN field.

The notification is Dynamicweb.Ecommerce.Notifications.Ecommerce.Product.BeforeSave.

My purpose is to check if the value entered is a valid EAN-13 value and if it's not, to prevent the save and display a validation error.

The validation error can be a simple Alert or a message next to the field.

How can I accomplish this?

I have tried using "Response.Write" with a javascript code rendering the alert but it does not seem to work. Is there any way I can change or initiate the validation message on that specific field?

Thank you,

Adrian


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

Anyone?

Thank you,

Adrian

 
Nicolai Pedersen
Reply

Hi Adrian

I have no good ideas. You can go for a ribbonbar addin and load a client side javascript that will validate the field before saving.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you,

I will look into this approach.

Thank you,

Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

The Add-on approach worked very well and we could do some of the needed checks with it.

Thank you for that.

I still need some help figuring out if and what can we do on a "Save" or "Save and Close" action.

What I am looking for is a validation of the data that is supposed to be saved. Something like the attached notification that is displayed upon "Save" or "Save and Close".

I have noticed there is an onClick function on the save buttons but I don't think that we can connect to it. That's why I am considering a notification like  Dynamicweb.Ecommerce.Notifications.Ecommerce.Product.BeforeSave.

Any suggestion is welcomed. Ninja or not :)

Thank you,

Adrian

notification.png
 
Nicolai Pedersen
Reply

If you have the addon approach working, you can manipulate the events of save and save and close buttons using javascript. You can add and remove click events and in that way control what Dynamicweb does.

If you attach your own click event to those 2 buttons and ensure they are first in the javascript event order, you can use event.preventDefault and return false inside your own click function if it fails. And then in your own javascript, you can do a server call using fetch to do your checks....

Kind of abstract description, but doable.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Abstract works good enough!

I will try this approach.

Thank you,

Adrian

 

You must be logged in to post in the forum