Allow the initial value of some fields to be tokenized (#6613)

Fixes #6613 
Fixes #6237
This commit is contained in:
jtkech
2016-10-27 22:15:47 +02:00
committed by Sébastien Ros
parent d59f5b511b
commit b160dc731d
11 changed files with 87 additions and 16 deletions

View File

@@ -77,9 +77,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(EmailField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@@ -41,7 +41,13 @@ namespace Orchard.DynamicForms.Drivers {
Id: "InputType",
Name: "InputType",
Title: "Input Type",
Description: T("The control to render when presenting the list of options.")));
Description: T("The control to render when presenting the list of options.")),
_DefaultValue: shape.Textbox(
Id: "DefaultValue",
Name: "DefaultValue",
Title: "Default Value",
Classes: new[] { "text", "large", "tokenized" },
Description: T("The default value of this enumeration field.")));
form._InputType.Items.Add(new SelectListItem { Text = T("Select List").Text, Value = "SelectList" });
form._InputType.Items.Add(new SelectListItem { Text = T("Multi Select List").Text, Value = "MultiSelectList" });
@@ -83,6 +89,13 @@ namespace Orchard.DynamicForms.Drivers {
var displayType = context.DisplayType;
var tokenData = context.GetTokenData();
// Allow the initially selected value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
if (element.PostedValue == null) {
var defaultValue = _tokenizer.Replace(element.DefaultValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
element.RuntimeValue = defaultValue;
}
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedOptions = _tokenizer.Replace(element.Options, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode }).ToArray();

View File

@@ -27,7 +27,7 @@ namespace Orchard.DynamicForms.Drivers {
Id: "Value",
Name: "Value",
Title: "Value",
Classes: new[] { "text", "medium" },
Classes: new[] { "text", "medium", "tokenized" },
Description: T("The value of this hidden field.")));
return form;
@@ -35,8 +35,12 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(HiddenField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedValue = element.RuntimeValue ?? string.Empty;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@@ -68,6 +68,12 @@ namespace Orchard.DynamicForms.Drivers {
Value: "{Content.Id}",
Description: T("Specify the expression to get the value of each option."),
Classes: new[]{"text", "large", "tokenized"}),
_DefaultValue: shape.Textbox(
Id: "DefaultValue",
Name: "DefaultValue",
Title: "Default Value",
Classes: new[] { "text", "large", "tokenized" },
Description: T("The default value of this query field.")),
_InputType: shape.SelectList(
Id: "InputType",
Name: "InputType",
@@ -122,6 +128,13 @@ namespace Orchard.DynamicForms.Drivers {
var displayType = context.DisplayType;
var tokenData = context.GetTokenData();
// Allow the initially selected value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
if (element.PostedValue == null) {
var defaultValue = _tokenizer.Replace(element.DefaultValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
element.RuntimeValue = defaultValue;
}
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData);
context.ElementShape.Options = GetOptions(element, context.DisplayType, queryId, tokenData).ToArray();

View File

@@ -67,6 +67,12 @@ namespace Orchard.DynamicForms.Drivers {
Value: "{Content.Id}",
Description: T("Specify the expression to get the value of each option."),
Classes: new[] { "text", "large", "tokenized" }),
_DefaultValue: shape.Textbox(
Id: "DefaultValue",
Name: "DefaultValue",
Title: "Default Value",
Classes: new[] { "text", "large", "tokenized" },
Description: T("The default value of this query field.")),
_InputType: shape.SelectList(
Id: "InputType",
Name: "InputType",
@@ -126,6 +132,13 @@ namespace Orchard.DynamicForms.Drivers {
var displayType = context.DisplayType;
var tokenData = context.GetTokenData();
// Allow the initially selected value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
if (element.PostedValue == null) {
var defaultValue = _tokenizer.Replace(element.DefaultValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
element.RuntimeValue = defaultValue;
}
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.TermOptions = GetTermOptions(element, context.DisplayType, taxonomyId, tokenData).ToArray();

View File

@@ -88,9 +88,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(TextArea element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@@ -83,9 +83,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(TextField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions {Encoding = ReplaceOptions.NoEncode});
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@@ -71,9 +71,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(UrlField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@@ -20,6 +20,10 @@ namespace Orchard.DynamicForms.Elements {
get { return _options.Value; }
}
public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}
public IEnumerable<string> RuntimeValues {
get { return _runtimeValues.Value; }
}

View File

@@ -27,6 +27,10 @@ namespace Orchard.DynamicForms.Elements {
get { return this.Retrieve(x => x.ValueExpression, () => "{Content.Id}"); }
}
public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}
public EnumerationValidationSettings ValidationSettings {
get { return Data.GetModel<EnumerationValidationSettings>(""); }
}

View File

@@ -34,6 +34,10 @@ namespace Orchard.DynamicForms.Elements {
set { this.Store(x => x.ValueExpression, value); }
}
public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}
public EnumerationValidationSettings ValidationSettings {
get { return Data.GetModel<EnumerationValidationSettings>(""); }
}