1
0
-1

I have a 'Text Field [Uppercase]' field (NameUpper) on the form, and I wanted to show a popup message whenever the value is changed in NameUpper field. To achieve that I have added a 'Business Rule [General Purpose]' field and in its Rules->Business->Business Rule I have written this script.

if (evt.evtName == 'change') {
    if (!$ISBLANK({NameUpper})){
        sfc.showAlert('Please ensure that you enter your name correctly.');
    }
}

 

Everything is working fine, only one problem. Form shows me two popup messages, seems like this script is fired twice for each change. I know it is an uppercase field so in the background some process will be changing the value entered by user to uppercase and then assigning it back to field, that is why it is being triggered twice.

However I just want to show popup once. Is there any solution to this?

 

Many Thanks in advance.

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      Hi Jye,

      Unfortunately I am unable to understand other two options you have mentioned, the inline messaging and using of modal dialogs. Also I was unable to use the timestamp thing as in script I can't find how to get timeStamp.

      so what I have done instead is 

      if (evt.evtName == 'change') {
          if (!$ISBLANK({NameUpper})){
              var alertShownAlready = sfc.getRawValue({AlertShown});
              if(alertShownAlready == 'false')
              {
                  sfc.showAlert('Please ensure that you enter your name correctly.');
                  sfc.setRawValue({AlertShown}, 'true')
              }
              else
              {
                  sfc.setRawValue({AlertShown}, 'false')
              }
          }
      }

       

      Ugly? I admit. but then it works. 

      anyone else who is trying to use this as workaround, make sure 'Trigger Type' of 'AlertShown' DataField is Static.

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi Touqeer thanks for pointing this out.

        I should be able to optimize the implementation in composer 5 to only fire a single change event for this widget in this case (I dont have the hooks in the composer 4.x codebase to be able to correctly do this)

        In regards to your workaround you seem to be assuming that you always will get 2 change events and are toggling the state, you need to bear in mind this wont always be the case. For instance if you correctly enter an uppercase name you will only get 1 event, similarly if the widget and rule are in a repeat and the repeat row count changes you may also only get a single change event

        If you are able to use the 4.4 release (where evt.evtData.oldValue was introduced for change events) then a more reliable way to distinguish between the 2 change events and ignore the unwanted one is as follows

         

        if (evt.evtName=='change' ) {

             var oldValue = evt.evtData != null ? evt.evtData.oldValue : null;

             var isUnwantedChange = oldValue != null && oldValue.toUpperCase()=={NameUpper};

             if (isUnwantedChange) {

                 // we have detected the internal change event sent to convert to uppercase, which we can ignore

                 return;

             }

             if (!$ISBLANK({NameUpper})) {

                 sfc.showAlert(....);

             }

        }

        1. Touqeer Ahsan

          Thanks Barker, mine composer version is 4.3.2, anyway I gave it a try and I am getting back 'undefined' from evt.evtData.oldValue. is there any method/Property in 4.3.2 which can give me value of field before applying uppercase on it? You are right in pointing out that I will not always be able to get 2 change events, however I made the initial value of the field to be 'false'. so even if I type my name in CAPS I will get that popup. yes for subsequent tries it will miss some, but I guess I have to live with this.

        CommentAdd your comment...
      2.  
        1
        0
        -1

        Hi Touqeer,

        Is there a reason you need to present this message as an alert? Alerts tend to irritate applicants, we would typically suggest using in-line messaging or a modal dialog instead. These have the added benefit of being able to be customized and configured so that they're not presented twice.

        Another option, in a multi-page form, is to present the name entered again in bold text with a message such as "Please ensure the name you have entered is correct, this will be used for ...." and an edit button that allows the applicant to update their name if it was incorrect.

        Finally, if you need to proceed with the alert, I would suggest storing a time stamp when the alert is first displayed and set a limit in your script so that it won't present the alert more than once in a 5s period (or whatever timeout you prefer).

         

        Regards,

        Jye

          CommentAdd your comment...