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. 

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

     

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

     

Children
  • 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)

    const currentItem = aras.itemsCache.getItem(itemId) || aras.itemsCache.getItemByXPath(`//Item[@id="${itemId}"]`);
    const classification = aras.getItemProperty(currentItem, 'classification', '');
    const parentpkg = aras.getItemProperty(currentItem, '_parent_package', '');
    const relatedproj = aras.getItemProperty(currentItem, '_relatedproject', '');
    
    //dialog box details
    const title = "Confirm Missing Value";
    const image = "../images/Warning.svg";
    const okButtonText = "Save Anyways";
    const dialogoptions = 
        {
            title,
            image,
            okButtonText,
            okButtonModifier: 'aras-button_secondary'
        };
    
    
    if (classification === "Tagged Component"){
        var message = "Tagged Components should be assigned to a Parent Package";
        if (value === null) {
            if (window.parent.ArasModules.Dialog.confirm(message, dialogoptions).then(function(res)
                {
                    switch(res){
                        case 'ok':
                            window.onSaveCommand();
                            return {
                                valid: true
                            };
                        default:
                            return {
                                valid: false,
                                validationMessage: `Assign ${_parent_package}. Tagged Items need to be assigned to a parent.`
                            };
                    }
                }
            ));
        }
    }
    
    //Otherwise, return a valid result.
    return {
    valid: true
    };

    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?

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

    var parentpkg = document.thisItem.getProperty("_parent_package");
    
    if (parentpkg === undefined) {
        aras.confirm("Parent Package is missing.  Should be assigned");
    }

    This is without any fancy styling at this point.

    Appreciate any additional thoughts on this.

  • 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

    function isCriticalFieldValid() {
        return false;
    }
    
    function myOnBeforeSave() {
        if (!isCriticalFieldValid()) return "Tagged Items need to be assigned to a parent.";
        else return null;
    }
    
    parent.registerCommandEventHandler(parent, myOnBeforeSave, 'before', 'save');
    

    if myOnBeforeSave returns any string Aras will show alert with this string and cancel saving the item. Otherwise the save will proceed.

  • 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 ;-)

  • It seems that the simple aras.confirm is truly modal. And this form OnLoad should work

    function myOnBeforeSave() {
        if (document.thisItem.getProperty("_parent_package") === "" && !aras.confirm("Tagged Components should be assigned to a Parent Package. Save anyway?"))
            return "Item is not saved.";
        else
            return null;
    }
    
    parent.registerCommandEventHandler(parent, myOnBeforeSave, 'before', 'save');
    

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

  • Hey 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?

  • I'm still on the free V12SP9 and this code works for it. Look in the browser console. May be there are some errors.

  • I can confirm Alaxalas solution to work in 12SP7 as well! 

    parent.registerCommandEventHandler is a nice variant for the Save overwrite. I also did some "Save" overwrites in the past, but solved it less elegant. Congrats for finding this gem!

    Thanks Jeff for the information about "Validate". Seems to be something new. This variant is not used anywhere in my prehistoric Innovator dinosaur. 

    So this is right now really a perfect moment for Aras to provide a new open release. Cause if the forum people cannot help with question regarding more recent Innovator versions, people like Jeff have to ask support more frequently which produce extra costs. So providing a new open release brings instant positive ROI !!!! Sunglasses