Skip to content

Commit

Permalink
提交Form失败时,用户填写的数据 #406
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriaWei committed Dec 30, 2020
1 parent bc71eb4 commit 0acae03
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IActionResult Submit(string FormId)
{
TempData["Message"] = _localize.Get("Form have submited");
}
return View();
return View(result.Result.Form);
}

[HttpPost, DefaultAuthorize(Policy = PermissionKeys.ManageFormData)]
Expand Down
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Address.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<div class="input-group" ng-class="'size-' + field.Size" style="display:block;">
<div class="row">
<div class="col-md-4">
Expand All @@ -18,7 +21,4 @@
</div>
</div>
</div>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Checkbox.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<div>
<div class="checkbox" ng-repeat="option in field.FieldOptions">
<label>
<input type="checkbox" ng-checked="option.DefaultSelected"> <span ng-bind="option.DisplayText" />
</label>
</div>
</div>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Date.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<div class="input-group" ng-class="'size-' + field.Size">
<input type="text" class="form-control" placeholder="{{field.Placeholder}}">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Dropdown.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<select class="form-control" ng-class="'size-' + field.Size">
<option>-- 请选择 --</option>
<option ng-repeat="op in field.FieldOptions" value="op.Value" ng-bind="op.DisplayText"></option>
</select>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Email.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<input class="form-control" type="text" ng-class="'size-' + field.Size" placeholder="{{field.Placeholder}}" />
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Label.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h4 class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></h4>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<p class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</p>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Number.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<input class="form-control" type="text" ng-class="'size-' + field.Size" placeholder="{{field.Placeholder}}" />
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Paragraph.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<textarea class="form-control" rows="3" cols="10" ng-class="'size-' + field.Size" placeholder="{{field.Placeholder}}"></textarea>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Phone.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<input class="form-control" type="text" ng-class="'size-' + field.Size" placeholder="{{field.Placeholder}}" />
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/Radio.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<div>
<div class="radio" ng-repeat="option in field.FieldOptions">
<label>
<input type="radio" name="radio" ng-checked="option.DefaultSelected"> <span ng-bind="option.DisplayText" />
</label>
</div>
</div>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/SingleLine.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<input class="form-control" type="text" ng-class="'size-' + field.Size" placeholder="{{field.Placeholder}}" />
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
6 changes: 3 additions & 3 deletions src/ZKEACMS.FormGenerator/DisplayTemplate/ValidCode.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<label class="control-label" ng-if="field.DisplayName" ng-bind="field.DisplayName"></label>
<span class="text-muted" ng-if="field.Description">
<span ng-bind="field.Description"></span>
</span>
<input class="form-control" type="text" ng-class="'size-' + field.Size" placeholder="{{field.Placeholder}}" />
<img src="/Validation/Code" style="margin-top:2px"/>
<dl ng-if="field.Description">
<dd ng-bind="field.Description"></dd>
</dl>
<button type="button" class="close" ng-click="removeField(field)" ng-if="Fields.length>1"><span aria-hidden="true">&times;</span></button>
10 changes: 9 additions & 1 deletion src/ZKEACMS.FormGenerator/Service/FormDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public override FormData Get(params object[] primaryKey)
var formData = base.Get(primaryKey);
formData.Form = _formService.Get(formData.FormId);
formData.Datas = _formDataItemService.Get(m => m.FormDataId == formData.ID).ToList();
MergeDataToForm(formData);
return formData;
}

private void MergeDataToForm(FormData formData)
{
if (formData.Form != null)
{
foreach (var item in formData.Form.FormFields)
Expand Down Expand Up @@ -94,8 +100,8 @@ public override FormData Get(params object[] primaryKey)

}
}
return formData;
}

public ServiceResult<FormData> SaveForm(IFormCollection formCollection, string formId)
{
var result = new ServiceResult<FormData>();
Expand Down Expand Up @@ -137,6 +143,8 @@ public ServiceResult<FormData> SaveForm(IFormCollection formCollection, string f
formData.Datas.Add(dataitem);
}
}
MergeDataToForm(formData);
result.Result = formData;
if (result.HasViolation)
{
return result;
Expand Down
6 changes: 5 additions & 1 deletion src/ZKEACMS.FormGenerator/Service/FormWidgetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public class FormWidgetService : SimpleWidgetService<FormWidget>

public override WidgetViewModelPart Display(WidgetDisplayContext widgetDisplayContext)
{
Form form = _formService.Get((widgetDisplayContext.Widget as FormWidget).FormID);
if(widgetDisplayContext.Model is Form form)
{
return widgetDisplayContext.ToWidgetViewModelPart(form);
}
form = _formService.Get((widgetDisplayContext.Widget as FormWidget).FormID);
return widgetDisplayContext.ToWidgetViewModelPart(form);
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/ZKEACMS.FormGenerator/Views/EditorTemplates/Form.Address.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
{
district = dist[2];
}

}
Dictionary<string, object> cityAttrs = new Dictionary<string, object> { { "class", "form-control" }, { "data-city", city ?? L("-- City --").Text } };
Dictionary<string, object> districtAttrs = new Dictionary<string, object> { { "class", "form-control" }, { "data-district", district ?? L("-- District --").Text } };
foreach (var item in Model.Attributes)
{
cityAttrs[item.Key] = item.Value;
districtAttrs[item.Key] = item.Value;
}
Model.Attributes.TryAdd("data-province", province ?? L("-- Province --").Text);
}
Expand All @@ -35,24 +41,24 @@
}
</label>
}
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<span class="text-muted">
<span>@Model.Description</span>
</span>
}
<div class="row" data-toggle="distpicker">
<div class="col-md-4">
@Html.DropDownList(Model.ID + "[0]", items, Model.Attributes)
@Html.ValidationMessage(Model.ID + "[0]")
</div>
<div class="col-md-4">
@Html.DropDownList(Model.ID + "[1]", items, new Dictionary<string, object> { { "class", "form-control" }, { "data-city", city ?? L("-- City --").Text } })
@Html.DropDownList(Model.ID + "[1]", items, cityAttrs)
@Html.ValidationMessage(Model.ID + "[1]")
</div>
<div class="col-md-4">
@Html.DropDownList(Model.ID + "[2]", items, new Dictionary<string, object> { { "class", "form-control" }, { "data-district", district ?? L("-- District --").Text } })
@Html.DropDownList(Model.ID + "[2]", items, districtAttrs)
@Html.ValidationMessage(Model.ID + "[2]")
</div>
</div>
@Html.ValidationMessage(Model.ID + "[0]")
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
}
</label>
}
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<span class="text-muted">
<span>@Model.Description</span>
</span>
}
<div>
@for (int i = 0; i < Model.FieldOptions.Count; i++)
{
Expand All @@ -28,12 +34,4 @@

</div>
@Html.ValidationMessage(Model.ID, L("Please select at least one option").Text)
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
}
</div>
14 changes: 6 additions & 8 deletions src/ZKEACMS.FormGenerator/Views/EditorTemplates/Form.Date.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
}
</label>
}
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<span class="text-muted">
<span>@Model.Description</span>
</span>
}
<div class="input-group">
@Html.TextBox(Model.ID, Model.Value, Model.Attributes)
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
@Html.ValidationMessage(Model.ID)
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
}
</label>
}
@Html.DropDownList(Model.ID, items, L("-- Select --").Text, Model.Attributes)
@Html.ValidationMessage(Model.ID)
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
<span class="text-muted">
<span>@Model.Description</span>
</span>
}
@Html.DropDownList(Model.ID, items, L("-- Select --").Text, Model.Attributes)
@Html.ValidationMessage(Model.ID)
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
}
</label>
}
@Html.TextBox(Model.ID, Model.Value, Model.Attributes)
@Html.ValidationMessage(Model.ID)
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
<span class="text-muted">
<span>@Model.Description</span>
</span>
}
@Html.TextBox(Model.ID, Model.Value, Model.Attributes)
@Html.ValidationMessage(Model.ID)
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
@Model.DisplayName
</h3>
}

@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
<p class="text-muted">
<span>@Model.Description</span>
</p>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
}
</label>
}
@Html.TextBox(Model.ID, Model.Value, Model.Attributes)
@Html.ValidationMessage(Model.ID)
@if (Model.Description.IsNotNullAndWhiteSpace())
{
<dl>
<dd>
@Model.Description
</dd>
</dl>
<span class="text-muted">
<span>@Model.Description</span>
</span>
}
@Html.TextBox(Model.ID, Model.Value, Model.Attributes)
@Html.ValidationMessage(Model.ID)
</div>

0 comments on commit 0acae03

Please sign in to comment.