Skip to content

Commit

Permalink
fix condition fields do not save the value if not selected
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanye committed Sep 30, 2017
1 parent 4196d69 commit 4f810b6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 27 deletions.
74 changes: 56 additions & 18 deletions Solution/PHS.Business/Implementation/FillIn/BaseFormFillIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public string FillIn(IDictionary<string, string> SubmitFields, Template Template
field.Errors = "{0} is a required field".FormatWith(field.Label);
errors.Add(field.Errors);
}

else
{
submissionFields.Add(field.TemplateFieldID.Value, value);
}
}

else
Expand All @@ -82,27 +87,60 @@ public string FillIn(IDictionary<string, string> SubmitFields, Template Template
{
foreach (var field in templateView.Fields.OrderBy(f => f.TemplateFieldID))
{
var value = field.SubmittedValue(formCollection);
if (field.ConditionTemplateFieldID.HasValue)
{
if (isConditionalFieldRequired(field, submissionFields))
{
var value = field.SubmittedValue(formCollection);

//if it's a file, save it to hard drive
if (field.FieldType == Constants.TemplateFieldType.FILEPICKER && !string.IsNullOrEmpty(value))
{
//var file = Request.Files[field.SubmittedFieldName()];
//var fileValueObject = value.GetFileValueFromJsonObject();

//if (fileValueObject != null)
//{
// if (UtilityHelper.UseCloudStorage())
// {
// this.SaveImageToCloud(file, fileValueObject.SaveName);
// }
// else
// {
// file.SaveAs(Path.Combine(HostingEnvironment.MapPath(fileValueObject.SavePath), fileValueObject.SaveName));
// }
//}
}
HandleTemplateFieldValue(field, value, entryId);
}
}

//if it's a file, save it to hard drive
if (field.FieldType == Constants.TemplateFieldType.FILEPICKER && !string.IsNullOrEmpty(value))
else
{
//var file = Request.Files[field.SubmittedFieldName()];
//var fileValueObject = value.GetFileValueFromJsonObject();

//if (fileValueObject != null)
//{
// if (UtilityHelper.UseCloudStorage())
// {
// this.SaveImageToCloud(file, fileValueObject.SaveName);
// }
// else
// {
// file.SaveAs(Path.Combine(HostingEnvironment.MapPath(fileValueObject.SavePath), fileValueObject.SaveName));
// }
//}
var value = field.SubmittedValue(formCollection);

//if it's a file, save it to hard drive
if (field.FieldType == Constants.TemplateFieldType.FILEPICKER && !string.IsNullOrEmpty(value))
{
//var file = Request.Files[field.SubmittedFieldName()];
//var fileValueObject = value.GetFileValueFromJsonObject();

//if (fileValueObject != null)
//{
// if (UtilityHelper.UseCloudStorage())
// {
// this.SaveImageToCloud(file, fileValueObject.SaveName);
// }
// else
// {
// file.SaveAs(Path.Combine(HostingEnvironment.MapPath(fileValueObject.SavePath), fileValueObject.SaveName));
// }
//}
}
HandleTemplateFieldValue(field, value, entryId);
}
HandleTemplateFieldValue(field, value, entryId);


}

HandleAdditionalInsert(templateView, Template, formCollection, entryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public void FillIn_NotSelectedConditionFieldWithRequiredShouldBeSave()
FormCollection submissionCollection = new FormCollection();
submissionCollection.Add("SubmitFields[1].RadioButton", "Yes");
submissionCollection.Add("SubmitFields[2].TextBox", "Testing 123");
submissionCollection.Add("SubmitFields[3].TextBox", null);
submissionCollection.Add("SubmitFields[3].TextBox", "not saved 123");

IDictionary<string, string> submissionFields = new System.Collections.Generic.Dictionary<string, string>();
submissionFields.Add("1", "1");
Expand All @@ -589,11 +589,10 @@ public void FillIn_NotSelectedConditionFieldWithRequiredShouldBeSave()

Assert.AreEqual(0, _unitOfWork.PreRegistrations.GetAll().Count());

Assert.AreEqual(3, templateViewModel.Entries.Count);
Assert.AreEqual(2, templateViewModel.Entries.Count);

Assert.AreEqual("Yes", templateViewModel.Entries[0].Value);
Assert.AreEqual("Testing 123", templateViewModel.Entries[1].Value);
Assert.AreEqual(null, templateViewModel.Entries[2].Value);
}

[TestMethod()]
Expand Down Expand Up @@ -661,9 +660,9 @@ public void FillIn_NotSelectedConditionFieldWithSubComponentRequiredShouldBeSave
FormCollection submissionCollection = new FormCollection();
submissionCollection.Add("SubmitFields[1].RadioButton", "Yes");
submissionCollection.Add("SubmitFields[2].RadioButton", "Yes");
submissionCollection.Add("SubmitFields[3].TextBox", null);
submissionCollection.Add("SubmitFields[3].TextBox", "i not supposed to be saved 1");
submissionCollection.Add("SubmitFields[4].TextBox", "Testing 123");
submissionCollection.Add("SubmitFields[5].TextBox", null);
submissionCollection.Add("SubmitFields[5].TextBox", "i not supposed to be saved 2");

IDictionary<string, string> submissionFields = new System.Collections.Generic.Dictionary<string, string>();
submissionFields.Add("1", "1");
Expand All @@ -679,13 +678,11 @@ public void FillIn_NotSelectedConditionFieldWithSubComponentRequiredShouldBeSave

Assert.AreEqual(0, _unitOfWork.PreRegistrations.GetAll().Count());

Assert.AreEqual(5, templateViewModel.Entries.Count);
Assert.AreEqual(3, templateViewModel.Entries.Count);

Assert.AreEqual("Yes", templateViewModel.Entries[0].Value);
Assert.AreEqual("Yes", templateViewModel.Entries[1].Value);
Assert.AreEqual(null, templateViewModel.Entries[2].Value);
Assert.AreEqual("Testing 123", templateViewModel.Entries[3].Value);
Assert.AreEqual(null, templateViewModel.Entries[4].Value);
Assert.AreEqual("Testing 123", templateViewModel.Entries[2].Value);
}

[TestMethod()]
Expand Down

0 comments on commit 4f810b6

Please sign in to comment.