Skip to content

Commit

Permalink
+ Fixed Workflow Form buttons incorrectly triggering validation when …
Browse files Browse the repository at this point in the history
…configured to cancel. (Fixes #4713)
  • Loading branch information
MrUpsideDown committed Sep 27, 2021
1 parent 69772c8 commit 4d7d627
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions Rock/Model/WorkflowActionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,11 @@ public class WorkflowActionFormUserAction
/// </remarks>
public static List<WorkflowActionFormUserAction> FromUriEncodedString( string encodedString )
{
Guid buttonCancelGuid = Rock.SystemGuid.DefinedValue.BUTTON_HTML_CANCEL.AsGuid();

var buttons = new List<WorkflowActionFormUserAction>();

var buttonList = Rock.Utility.RockSerializableList.FromUriEncodedString( encodedString, StringSplitOptions.RemoveEmptyEntries );

// Without any other way of determining this, assume that the built-in Cancel button is the only action that does not cause validation.
var nonValidationButtonList = new List<Guid> { buttonCancelGuid };
var cancelButtonList = GetCancelButtonGuidList();

foreach ( var buttonDefinitionText in buttonList.List )
{
Expand All @@ -605,18 +602,8 @@ public static List<WorkflowActionFormUserAction> FromUriEncodedString( string en
button.ButtonTypeGuid = Rock.SystemGuid.DefinedValue.BUTTON_HTML_PRIMARY;
}

// Determine if the button causes form validation.
button.CausesValidation = !nonValidationButtonList.Contains( button.ButtonTypeGuid.AsGuid() );

if ( button.ButtonTypeGuid.AsGuid() == buttonCancelGuid )
{
button.CausesValidation = false;
}
else
{
// By default, assume that an action button triggers validation of the form.
button.CausesValidation = true;
}
// If the button is not a Cancel button, flag it as causing form validation.
button.CausesValidation = !cancelButtonList.Contains( button.ButtonTypeGuid.AsGuid() );

// Button Activity
button.ActivateActivityTypeGuid = nameValueResponse.Length > 2 ? nameValueResponse[2] : string.Empty;
Expand All @@ -629,6 +616,41 @@ public static List<WorkflowActionFormUserAction> FromUriEncodedString( string en

return buttons;
}

/// <summary>
/// Get the set of workflow action buttons that are configured to perform a cancel function.
/// </summary>
/// <returns></returns>
private static List<Guid> GetCancelButtonGuidList()
{
// Add the default Cancel button.
var cancelButtonList = new List<Guid> { Rock.SystemGuid.DefinedValue.BUTTON_HTML_CANCEL.AsGuid() };

// Add other buttons that have been configured to disable validation.
// In accordance with the Rock documentation, button validation can be disabled
// by replacing the text "{{ ButtonClick }}" with "return true;" in the Button HTML Attribute.
// Add any buttons with this configuration to the collection of Cancel buttons.
var buttonType = DefinedTypeCache.Get( Rock.SystemGuid.DefinedType.BUTTON_HTML );

foreach ( var buttonDefinedValue in buttonType.DefinedValues )
{
var buttonHtml = buttonDefinedValue.GetAttributeValue( "ButtonHTML" );

if ( !buttonHtml.IsNullOrWhiteSpace() )
{
buttonHtml = buttonHtml.ToLower().Replace( " ", "" );

if ( !buttonHtml.Contains( "{{buttonclick}}" )
&& buttonHtml.Contains( "onclick=\"returntrue;\"" ) )
{
cancelButtonList.Add( buttonDefinedValue.Guid );
}
}
}

return cancelButtonList;

}
}

#region Enums
Expand Down

0 comments on commit 4d7d627

Please sign in to comment.