mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-20 19:03:25 +08:00
Squash
This commit is contained in:
@@ -65,8 +65,9 @@ Scenario: Creating and using Boolean fields
|
||||
# The value should be required
|
||||
When I go to "Admin/ContentTypes/Edit/Event"
|
||||
And I fill in
|
||||
| name | value |
|
||||
| Fields[0].BooleanFieldSettings.Optional | false |
|
||||
| name | value |
|
||||
| Fields[0].BooleanFieldSettings.Optional | false |
|
||||
| Fields[0].BooleanFieldSettings.DefaultValue | Neutral |
|
||||
And I fill in
|
||||
| name | value |
|
||||
| Fields[0].BooleanFieldSettings.NotSetLabel | May be |
|
||||
|
17
src/Orchard.Specs/Boolean.feature.cs
generated
17
src/Orchard.Specs/Boolean.feature.cs
generated
@@ -193,6 +193,9 @@ this.ScenarioSetup(scenarioInfo);
|
||||
table6.AddRow(new string[] {
|
||||
"Fields[0].BooleanFieldSettings.Optional",
|
||||
"false"});
|
||||
table6.AddRow(new string[] {
|
||||
"Fields[0].BooleanFieldSettings.DefaultValue",
|
||||
"Neutral"});
|
||||
#line 67
|
||||
testRunner.And("I fill in", ((string)(null)), table6, "And ");
|
||||
#line hidden
|
||||
@@ -202,7 +205,7 @@ this.ScenarioSetup(scenarioInfo);
|
||||
table7.AddRow(new string[] {
|
||||
"Fields[0].BooleanFieldSettings.NotSetLabel",
|
||||
"May be"});
|
||||
#line 70
|
||||
#line 71
|
||||
testRunner.And("I fill in", ((string)(null)), table7, "And ");
|
||||
#line hidden
|
||||
TechTalk.SpecFlow.Table table8 = new TechTalk.SpecFlow.Table(new string[] {
|
||||
@@ -211,11 +214,11 @@ this.ScenarioSetup(scenarioInfo);
|
||||
table8.AddRow(new string[] {
|
||||
"Fields[0].BooleanFieldSettings.SelectionMode",
|
||||
"Radiobutton"});
|
||||
#line 73
|
||||
#line 74
|
||||
testRunner.And("I fill in", ((string)(null)), table8, "And ");
|
||||
#line 76
|
||||
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
|
||||
#line 77
|
||||
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
|
||||
#line 78
|
||||
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
|
||||
#line hidden
|
||||
TechTalk.SpecFlow.Table table9 = new TechTalk.SpecFlow.Table(new string[] {
|
||||
@@ -224,11 +227,11 @@ this.ScenarioSetup(scenarioInfo);
|
||||
table9.AddRow(new string[] {
|
||||
"Event.Active.Value",
|
||||
""});
|
||||
#line 78
|
||||
#line 79
|
||||
testRunner.And("I fill in", ((string)(null)), table9, "And ");
|
||||
#line 81
|
||||
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
|
||||
#line 82
|
||||
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
|
||||
#line 83
|
||||
testRunner.Then("I should see \"The field Active is mandatory.\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
|
||||
#line hidden
|
||||
this.ScenarioCleanup();
|
||||
|
@@ -48,7 +48,12 @@ namespace Orchard.Fields.Drivers {
|
||||
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
||||
var settings = field.PartFieldDefinition.Settings.GetModel<BooleanFieldSettings>();
|
||||
if (!settings.Optional && !field.Value.HasValue) {
|
||||
updater.AddModelError(field.Name, T("The field {0} is mandatory.", T(field.DisplayName)));
|
||||
if (settings.DefaultValue.HasValue) {
|
||||
field.Value = settings.DefaultValue;
|
||||
}
|
||||
else {
|
||||
updater.AddModelError(field.Name, T("The field {0} is mandatory.", T(field.DisplayName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ using Orchard.Localization;
|
||||
using Orchard.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Orchard.Fields.Drivers {
|
||||
public class EnumerationFieldDriver : ContentFieldDriver<EnumerationField> {
|
||||
@@ -40,7 +41,7 @@ namespace Orchard.Fields.Drivers {
|
||||
() => {
|
||||
if (field.Value == null) {
|
||||
var settings = field.PartFieldDefinition.Settings.GetModel<EnumerationFieldSettings>();
|
||||
if (!String.IsNullOrEmpty(settings.DefaultValue)) {
|
||||
if (!String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
||||
}
|
||||
}
|
||||
@@ -52,6 +53,16 @@ namespace Orchard.Fields.Drivers {
|
||||
protected override DriverResult Editor(ContentPart part, EnumerationField field, IUpdateModel updater, dynamic shapeHelper) {
|
||||
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
||||
var settings = field.PartFieldDefinition.Settings.GetModel<EnumerationFieldSettings>();
|
||||
|
||||
if (field.SelectedValues.Length == 0 && !String.IsNullOrWhiteSpace(settings.DefaultValue) && !String.IsNullOrWhiteSpace(settings.Options)) {
|
||||
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
||||
|
||||
string[] options = settings.Options.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var selectedValues = field.SelectedValues.ToList();
|
||||
selectedValues.RemoveAll(value => !options.Any(value.Equals));
|
||||
field.SelectedValues = selectedValues.ToArray();
|
||||
}
|
||||
|
||||
if (settings.Required && field.SelectedValues.Length == 0) {
|
||||
updater.AddModelError(field.Name, T("The field {0} is mandatory", T(field.DisplayName)));
|
||||
}
|
||||
|
@@ -3,47 +3,49 @@
|
||||
@{
|
||||
var settings = Model.PartFieldDefinition.Settings.GetModel<EnumerationFieldSettings>();
|
||||
string[] options = (!String.IsNullOrWhiteSpace(settings.Options)) ? settings.Options.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None) : new string[] { T("Select an option").ToString() };
|
||||
var isRequired = settings.Required && String.IsNullOrWhiteSpace(settings.DefaultValue);
|
||||
}
|
||||
<fieldset>
|
||||
<label for="@Html.FieldIdFor(m => m.Value)" @if(settings.Required) { <text>class="required"</text> }>@Model.DisplayName</label>
|
||||
<label for="@Html.FieldIdFor(m => m.Value)" @if (settings.Required) { <text> class="required" </text> }>@Model.DisplayName</label>
|
||||
@switch (settings.ListMode) {
|
||||
case ListMode.Dropdown:
|
||||
@Html.DropDownListFor(m => m.Value, new SelectList(options, Model.Value), settings.Required ? new {required = "required"} : null)
|
||||
@Html.DropDownListFor(m => m.Value, new SelectList(options, Model.Value), isRequired ? new { required = "required" } : null)
|
||||
break;
|
||||
|
||||
|
||||
case ListMode.Radiobutton:
|
||||
foreach (var option in options) {
|
||||
if (string.IsNullOrWhiteSpace(option)) {
|
||||
<label>@Html.RadioButton("Value", "", string.IsNullOrWhiteSpace(Model.Value), settings.Required ? new {required = "required"} : null)<i>@T("unset")</i></label>
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(option)) {
|
||||
<label>@Html.RadioButton("Value", "", string.IsNullOrWhiteSpace(Model.Value), isRequired ? new { required = "required" } : null)<i>@T("unset")</i></label> }
|
||||
else {
|
||||
<label>@Html.RadioButton("Value", option, (option == Model.Value), settings.Required ? new {required = "required"} : null)@option</label>
|
||||
}
|
||||
<label>@Html.RadioButton("Value", option, (option == Model.Value), isRequired ? new { required = "required" } : null)@option</label> }
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ListMode.Listbox:
|
||||
<input name="@Html.FieldNameFor(m => m.SelectedValues)" type="hidden" />
|
||||
@Html.ListBoxFor(m => m.SelectedValues, new MultiSelectList(options, Model.SelectedValues), settings.Required ? new {required = "required"} : null)
|
||||
@Html.ListBoxFor(m => m.SelectedValues, new MultiSelectList(options, Model.SelectedValues), isRequired ? new { required = "required" } : null)
|
||||
break;
|
||||
|
||||
case ListMode.Checkbox:
|
||||
int index = 0;
|
||||
<input name="@Html.FieldNameFor(m => m.SelectedValues)" type="hidden" />
|
||||
foreach (var option in options) {
|
||||
index++;
|
||||
if (!string.IsNullOrWhiteSpace(option)) {
|
||||
foreach (var option in options) {
|
||||
index++;
|
||||
if (!string.IsNullOrWhiteSpace(option)) {
|
||||
<div>
|
||||
<input type="checkbox" name="@Html.FieldNameFor(m => m.SelectedValues)" value="@option" @((Model.SelectedValues != null && Model.SelectedValues.Contains(option)) ? "checked=\"checked\"" : "") class="check-box" id="@Html.FieldIdFor(m => m.SelectedValues)-@index" @if(settings.Required) {<text> required="required"</text> } />
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.SelectedValues)-@index">@T(option)</label>
|
||||
<input type="checkbox" name="@Html.FieldNameFor(m => m.SelectedValues)" value="@option" @((Model.SelectedValues != null && Model.SelectedValues.Contains(option)) ? "checked=\"checked\"" : "") class="check-box" id="@Html.FieldIdFor(m => m.SelectedValues)-@index" />
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.SelectedValues)-@index">@T(option)</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@Html.ValidationMessageFor(m => m.SelectedValues)
|
||||
@if (HasText(settings.Hint)) {
|
||||
<span class="hint">@settings.Hint</span>
|
||||
<span class="hint">@settings.Hint</span>
|
||||
}
|
||||
</fieldset>
|
||||
@if (!String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||
<span class="hint">@T("If no option is selected then the default value will be used.")</span>
|
||||
}
|
||||
</fieldset>
|
Reference in New Issue
Block a user