Forum Discussion

jeff_stroh's avatar
jeff_stroh
Ideator I
3 years ago

Property validation - Dialog to Confirm Ok or Not

Hello All,

I've been struggling with a property validation use-case and I'm sure it's something that'd be useful to lots of folks.

Have a working server event that blocks the user from proceeding if a certain property is left blank; however there may be cases when the user wants to proceed anyways with that field blank.  As far as I've read, there's no confirmation dialog available via the Server Events, only error ones.

So...  looked at a Client-side event on the property validation.  Good news is I'm able to get this event to fire.  The bad news is the field is an "Item" and when an item is selected, it doesn't seem to actually save the reference.

I'm doing this on a "Validate" event on the property itself.

Has anyone done anything like this or have a suggestion?

I don't really care if it's done against the property or a form, just need a way to highlight that something is blank and shouldn't be most of the time!

Thanks in advance. 

10 Replies

  • 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, ...).

     

    • jeff_stroh's avatar
      jeff_stroh
      Ideator I

      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?

      • alaxala's avatar
        alaxala
        Ideator 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.