#16855: When adding a field you may no longer use spaces or special characters (breaks overrides and searching). Added a 'hint' to the UI for the format.

--HG--
branch : dev
This commit is contained in:
Dave Reed
2010-12-01 13:06:37 -08:00
parent 59a874aa28
commit 6d52280a16
2 changed files with 11 additions and 4 deletions

View File

@@ -206,6 +206,7 @@ namespace Orchard.ContentTypes.Services {
}
public void AddFieldToPart(string fieldName, string fieldTypeName, string partName) {
fieldName = SafeName(fieldName);
_contentDefinitionManager.AlterPartDefinition(partName, partBuilder =>
partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName))
);
@@ -215,9 +216,8 @@ namespace Orchard.ContentTypes.Services {
_contentDefinitionManager.AlterPartDefinition(partName, typeBuilder => typeBuilder.RemoveField(fieldName));
}
//gratuitously stolen from the RoutableService
public string GenerateName(string name) {
if ( string.IsNullOrWhiteSpace(name) )
private static string SafeName(string name) {
if (string.IsNullOrWhiteSpace(name))
return String.Empty;
var dissallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""<>]+");
@@ -227,6 +227,12 @@ namespace Orchard.ContentTypes.Services {
if (name.Length > 128)
name = name.Substring(0, 128);
return name;
}
//gratuitously stolen from the RoutableService
public string GenerateName(string name) {
name = SafeName(name);
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
name = VersionName(name);

View File

@@ -4,8 +4,9 @@
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<fieldset>
<label for="DisplayName">@T("Display Name")</label>
<label for="DisplayName">@T("Name")</label>
@Html.TextBoxFor(m => m.DisplayName, new {@class = "textMedium", autofocus = "autofocus"})
<span class="hint">@T("Use no spaces or special characters. For example, \"MyCustomField\"")</span>
</fieldset>
<fieldset>
<label for="FieldTypeName">@T("Field Type")</label>