mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Correcting checkbox element such that it maintains postback state.
This fixes the issue where a checkbox would lose its checked state after posting back and a model validation occurs.
This commit is contained in:
@@ -26,11 +26,19 @@ namespace Orchard.DynamicForms.Elements {
|
||||
get { return State.Get("Value"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The runtime value for this element. This is either the default value, or the submitted value.
|
||||
/// </summary>
|
||||
public string RuntimeValue {
|
||||
get { return _runtimeValue.Value; }
|
||||
set { _runtimeValue = new Lazy<string>(() => value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value posted back for this element.
|
||||
/// </summary>
|
||||
public string PostedValue { get; set; }
|
||||
|
||||
public string FormBindingContentType {
|
||||
get { return State.Get("FormBindingContentType"); }
|
||||
set { State["FormBindingContentType"] = value; }
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Orchard.DynamicForms.Handlers {
|
||||
var combinedValues = String.Join(",", items);
|
||||
context.Output[key] = combinedValues;
|
||||
element.RuntimeValue = combinedValues;
|
||||
element.PostedValue = combinedValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@
|
||||
tagBuilder.Attributes["name"] = element.Name;
|
||||
tagBuilder.Attributes["value"] = Model.TokenizedValue;
|
||||
tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(element.PostedValue)) {
|
||||
tagBuilder.Attributes["checked"] = "checked";
|
||||
}
|
||||
}
|
||||
@if (element.ShowLabel) {
|
||||
<label>
|
||||
|
||||
Reference in New Issue
Block a user