Skip to content

Commit

Permalink
+ (Event) Updated Registration Template Detail block to not allow add…
Browse files Browse the repository at this point in the history
…ing duplicate form fields. (Fixes #5372)
  • Loading branch information
cabal95 committed Oct 5, 2023
1 parent 73aa58f commit 5156bb9
Showing 1 changed file with 58 additions and 7 deletions.
65 changes: 58 additions & 7 deletions RockWeb/Blocks/Event/RegistrationTemplateDetail.ascx.cs
Expand Up @@ -2930,10 +2930,6 @@ private void LoadDropDowns( RockContext rockContext )

ddlFieldSource.BindToEnum<RegistrationFieldSource>();

ddlPersonField.BindToEnum<RegistrationPersonFieldType>( sortAlpha: true );
ddlPersonField.Items.Remove( ddlPersonField.Items.FindByValue( "0" ) );
ddlPersonField.Items.Remove( ddlPersonField.Items.FindByValue( "1" ) );

rblFeeType.BindToEnum<RegistrationFeeType>();

ddlSignatureDocumentTemplate.Items.Clear();
Expand Down Expand Up @@ -3143,6 +3139,17 @@ private void ShowRegistrantFormFieldEdit( Guid formGuid, Guid formFieldGuid )

var fieldList = FormFieldsState[formGuid];

// Find all the existing fields for the various types.
var personPropertyFields = FormFieldsState.SelectMany( forms => forms.Value )
.Where( field => field.FieldSource == RegistrationFieldSource.PersonField )
.ToList();
var personAttributeFields = FormFieldsState.SelectMany( forms => forms.Value )
.Where( field => field.FieldSource == RegistrationFieldSource.PersonAttribute )
.ToList();
var groupAttributeFields = FormFieldsState.SelectMany( forms => forms.Value )
.Where( field => field.FieldSource == RegistrationFieldSource.GroupMemberAttribute )
.ToList();

RegistrationTemplateFormField formField = fieldList.FirstOrDefault( a => a.Guid.Equals( formFieldGuid ) );
if ( formField == null )
{
Expand All @@ -3162,16 +3169,41 @@ private void ShowRegistrantFormFieldEdit( Guid formGuid, Guid formFieldGuid )
ceFormFieldPreHtml.Text = formField.PreText;
ceFormFieldPostHtml.Text = formField.PostText;
ddlFieldSource.SetValue( formField.FieldSource.ConvertToInt() );
ddlPersonField.SetValue( formField.PersonFieldType.ConvertToInt() );
lPersonField.Text = formField.PersonFieldType.ConvertToString();

// Populate the Person Field picker and then remove any fields
// that already exist on any form.
ddlPersonField.Items.Clear();
ddlPersonField.BindToEnum<RegistrationPersonFieldType>( sortAlpha: true );

foreach ( var field in personPropertyFields )
{
var existingItem = ddlPersonField.Items.FindByValue( field.PersonFieldType.ConvertToInt().ToString() );
if ( existingItem != null && field.Guid != formFieldGuid )
{
ddlPersonField.Items.Remove( existingItem );
}
}

// Populate the Person Attribute picker and skip any attributes
// that already exist on the form.
ddlPersonAttributes.Items.Clear();
var person = new Person();
person.LoadAttributes();
foreach ( var attr in person.Attributes
.OrderBy( a => a.Value.Name )
.Select( a => a.Value ) )
{
// Check if this attribute already exists on any form and
// is not the same field we are editing.
var existingItem = personAttributeFields
.Where( paf => paf.Guid != formFieldGuid && paf.AttributeId == attr.Id )
.FirstOrDefault();

if ( existingItem != null )
{
continue;
}

if ( attr.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
var listItem = new ListItem( attr.Name, attr.Id.ToString() );
Expand All @@ -3180,16 +3212,30 @@ private void ShowRegistrantFormFieldEdit( Guid formGuid, Guid formFieldGuid )
}
}

// Populate the Group Member Attribute picker and skip any attributes
// that already exist on the form.
ddlGroupTypeAttributes.Items.Clear();
var group = new Group();
group.GroupTypeId = gtpGroupType.SelectedGroupTypeId ?? 0;
var groupMember = new GroupMember();
groupMember.Group = group;
groupMember.GroupTypeId = gtpGroupType.SelectedGroupTypeId ?? 0;
groupMember.LoadAttributes();
foreach ( var attr in groupMember.Attributes
.OrderBy( a => a.Value.Name )
.Select( a => a.Value ) )
{
// Check if this attribute already exists on any form and
// is not the same field we are editing.
var existingItem = groupAttributeFields
.Where( paf => paf.Guid != formFieldGuid && paf.AttributeId == attr.Id )
.FirstOrDefault();

if ( existingItem != null )
{
continue;
}

if ( attr.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
ddlGroupTypeAttributes.Items.Add( new ListItem( attr.Name, attr.Id.ToString() ) );
Expand All @@ -3199,7 +3245,12 @@ private void ShowRegistrantFormFieldEdit( Guid formGuid, Guid formFieldGuid )
var attribute = new Attribute();
attribute.FieldTypeId = FieldTypeCache.Get( Rock.SystemGuid.FieldType.TEXT ).Id;

if ( formField.FieldSource == RegistrationFieldSource.PersonAttribute )
if ( formField.FieldSource == RegistrationFieldSource.PersonField )
{
ddlPersonField.SetValue( formField.PersonFieldType.ConvertToInt() );
lPersonField.Text = formField.PersonFieldType.ConvertToString();
}
else if ( formField.FieldSource == RegistrationFieldSource.PersonAttribute )
{
ddlPersonAttributes.SetValue( formField.AttributeId );
}
Expand Down

0 comments on commit 5156bb9

Please sign in to comment.