Skip to content

Commit

Permalink
Allow the initial value of some fields to be tokenized (#6613)
Browse files Browse the repository at this point in the history
Fixes #6613 
Fixes #6237
  • Loading branch information
jtkech authored and sebastienros committed Oct 27, 2016
1 parent d59f5b5 commit b160dc7
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ protected override void DescribeForm(DescribeContext context) {
}

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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ protected override void DescribeForm(DescribeContext context) {
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" });
Expand Down Expand Up @@ -83,6 +89,13 @@ protected override void OnDisplaying(Enumeration element, ElementDisplayingConte
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ protected override void DescribeForm(DescribeContext context) {
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;
});
}

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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ protected override void DescribeForm(DescribeContext context) {
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",
Expand Down Expand Up @@ -122,6 +128,13 @@ protected override void OnDisplaying(Query element, ElementDisplayingContext con
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ protected override void DescribeForm(DescribeContext context) {
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",
Expand Down Expand Up @@ -126,6 +132,13 @@ protected override void OnDisplaying(Taxonomy element, ElementDisplayingContext
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ protected override void DescribeForm(DescribeContext context) {
}

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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ protected override void DescribeForm(DescribeContext context) {
}

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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ protected override void DescribeForm(DescribeContext context) {
}

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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public IEnumerable<SelectListItem> Options {
get { return _options.Value; }
}

public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}

public IEnumerable<string> RuntimeValues {
get { return _runtimeValues.Value; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public string ValueExpression {
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>(""); }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public string ValueExpression {
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>(""); }
}
Expand Down

0 comments on commit b160dc7

Please sign in to comment.