Forum Discussion
What event type do you use right now? Regarding the "not working save" you maybe have to "return true" or update the dom to make the item field work correct. But hard to tell without knowing exactly what you do right..
You write that you want to "block the user from proceeding". What kind of proceeding? Saving the item? Promote? Use of custom Action?
I use one solution where I have replaced an existing CUI button for promote with a variant that shows a confirm dialog to inform them that "xy is not perfect and if the want to continue anyway". But it´s a solution that requires some work, cause often you have to replace multiple buttons (grid, form, ...).
So I solved this after a deeper dive on the Programmer's Guide. A few things unlocked, 1) the Validate event expects a true or false to come out of it as the result and 2) the way that properties are fetched isn't quite the same as what you'd use on a form.
I also got it to use the Aras dialog (thanks to this thread! https://community.aras.com/f/getting-started/37434/aras-confirm-dialog---are-there-any-alternatives-or-updates-to-improve-the-lock-feel)
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:abbc25d8-441a-4869-921a-23847c1edb82:type=javascript&text=const%20currentItem%20%3D%20aras.itemsCache.getItem%28itemId%29%20%7C%7C%20aras.itemsCache.getItemByXPath%28%60%2F%2FItem%5B%40id%3D%22%24%7BitemId%7D%22%5D%60%29%3B%0D%0Aconst%20classification%20%3D%20aras.getItemProperty%28currentItem%2C%20%27classification%27%2C%20%27%27%29%3B%0D%0Aconst%20parentpkg%20%3D%20aras.getItemProperty%28currentItem%2C%20%27_parent_package%27%2C%20%27%27%29%3B%0D%0Aconst%20relatedproj%20%3D%20aras.getItemProperty%28currentItem%2C%20%27_relatedproject%27%2C%20%27%27%29%3B%0D%0A%0D%0A%2F%2Fdialog%20box%20details%0D%0Aconst%20title%20%3D%20%22Confirm%20Missing%20Value%22%3B%0D%0Aconst%20image%20%3D%20%22..%2Fimages%2FWarning.svg%22%3B%0D%0Aconst%20okButtonText%20%3D%20%22Save%20Anyways%22%3B%0D%0Aconst%20dialogoptions%20%3D%20%0D%0A%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20title%2C%0D%0A%20%20%20%20%20%20%20%20image%2C%0D%0A%20%20%20%20%20%20%20%20okButtonText%2C%0D%0A%20%20%20%20%20%20%20%20okButtonModifier%3A%20%27aras-button_secondary%27%0D%0A%20%20%20%20%7D%3B%0D%0A%0D%0A%0D%0Aif%20%28classification%20%3D%3D%3D%20%22Tagged%20Component%22%29%7B%0D%0A%20%20%20%20var%20message%20%3D%20%22Tagged%20Components%20should%20be%20assigned%20to%20a%20Parent%20Package%22%3B%0D%0A%20%20%20%20if%20%28value%20%3D%3D%3D%20null%29%20%7B%0D%0A%20%20%20%20%20%20%20%20if%20%28window.parent.ArasModules.Dialog.confirm%28message%2C%20dialogoptions%29.then%28function%28res%29%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20switch%28res%29%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20case%20%27ok%27%3A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20window.onSaveCommand%28%29%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20valid%3A%20true%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20default%3A%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20valid%3A%20false%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20validationMessage%3A%20%60Assign%20%24%7B_parent_package%7D.%20Tagged%20Items%20need%20to%20be%20assigned%20to%20a%20parent.%60%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%29%29%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0A%2F%2FOtherwise%2C%20return%20a%20valid%20result.%0D%0Areturn%20%7B%0D%0Avalid%3A%20true%0D%0A%7D%3B]
The validation message part doesn't actually work at the moment, but it's not holding me up anyways. Figured I'd share the code in case anyone else might be interested.
But... my main hang-up now is that if the user doesn't pick on that field, it doesn't seem that the validation event is run. So if they edit everything else, but don't pick on that field (which isn't set to required, because it's context-specific required), it doesn't alert them. Does anyone know of a way to have a method to check for validity on all the fields before a Save or Done?
- jeff_stroh3 years agoIdeator I
Follow-up on this is have been able to get a dialog to trigger on an empty field using a Form-linked event; however it only seems to work when the event is "onFormPopulated". When it's set to "onBeforeUnload" (which I'm presuming is meant to be before it's unlocked, but can't find documentation saying that), it never seems to trigger.
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:5bab9a13-c679-464e-85df-d32b82e8b298:type=javascript&text=var%20parentpkg%20%3D%20document.thisItem.getProperty%28%22_parent_package%22%29%3B%0D%0A%0D%0Aif%20%28parentpkg%20%3D%3D%3D%20undefined%29%20%7B%0D%0A%20%20%20%20aras.confirm%28%22Parent%20Package%20is%20missing.%20%20Should%20be%20assigned%22%29%3B%0D%0A%7D]
This is without any fancy styling at this point.
Appreciate any additional thoughts on this.
- alaxala3 years agoIdeator I
I don't think it's possible to implement such a scenario since modern browsers don't support modal dialogs. Your validation is not working because Dialog.confirm is not modal. Your callback function with switch/case is called when the user presses some button, but by this time the validation method has already returned true.
You can register your own client OnBeforeSave handler but still can't wait user input from any dialog. To register handler attach something like this to form OnLoad event
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:6f9e89fe-c8eb-4fc7-99a1-17428685eff4:type=javascript&text=function%20isCriticalFieldValid%28%29%20%7B%0D%0A%20%20%20%20return%20false%3B%0D%0A%7D%0D%0A%0D%0Afunction%20myOnBeforeSave%28%29%20%7B%0D%0A%20%20%20%20if%20%28%21isCriticalFieldValid%28%29%29%20return%20%22Tagged%20Items%20need%20to%20be%20assigned%20to%20a%20parent.%22%3B%0D%0A%20%20%20%20else%20return%20null%3B%0D%0A%7D%0D%0A%0D%0Aparent.registerCommandEventHandler%28parent%2C%20myOnBeforeSave%2C%20%27before%27%2C%20%27save%27%29%3B%0D%0A]
if myOnBeforeSave returns any string Aras will show alert with this string and cancel saving the item. Otherwise the save will proceed.
- AngelaIp3 years agoIdeator I
I can confirm that typical error or confirm dialog doesn´t work for onFormUnload/onUnload events.
But the regular notifys should work (the one in the top right corner).If nothing works, you could still use simple visual hints, e.g.
#1: custom CSS to show item placeholder if item property is empty
#2: Custom html element that is hidden/shown with an onFormPopulated event
@Jeff: One question: In which sample did you actually find this piece of code?
return {
valid: true
};I never have seen Aras returning a "valid". Just true or false, but nothing like this. I am so confused ;-)
- jeff_stroh3 years agoIdeator I
Hey AngelaIp good thoughts! I may end up going that route if I can't get a dialog to work. I found that in the V15 Programmer's Guide, section 8.41. " How to Use the "Validate" Data Store Event". Double checked and it's NOT in the V12 Programmer's Guide, so don't know if it's a new command or simply one which wasn't documented before?
- alaxala3 years agoIdeator I
It seems that the simple aras.confirm is truly modal. And this form OnLoad should work
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:f3aca68b-a890-4288-b123-126193abc438:type=javascript&text=function%20myOnBeforeSave%28%29%20%7B%0D%0A%20%20%20%20if%20%28document.thisItem.getProperty%28%22_parent_package%22%29%20%3D%3D%3D%20%22%22%20%26%26%20%21aras.confirm%28%22Tagged%20Components%20should%20be%20assigned%20to%20a%20Parent%20Package.%20Save%20anyway%3F%22%29%29%0D%0A%20%20%20%20%20%20%20%20return%20%22Item%20is%20not%20saved.%22%3B%0D%0A%20%20%20%20else%0D%0A%20%20%20%20%20%20%20%20return%20null%3B%0D%0A%7D%0D%0A%0D%0Aparent.registerCommandEventHandler%28parent%2C%20myOnBeforeSave%2C%20%27before%27%2C%20%27save%27%29%3B%0D%0A]
- jeff_stroh3 years agoIdeator I
alaxala thanks for the reply. I put just the above and set the event to "onLoad". It doesn't pop up a message though... This is in Chrome and we have a V15 instance.