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:
Sipke Schoorstra
2014-11-24 14:50:44 -08:00
parent 8b1b2bfc1b
commit dc9490d895
3 changed files with 13 additions and 0 deletions

View File

@@ -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; }

View File

@@ -22,6 +22,7 @@ namespace Orchard.DynamicForms.Handlers {
var combinedValues = String.Join(",", items);
context.Output[key] = combinedValues;
element.RuntimeValue = combinedValues;
element.PostedValue = combinedValues;
}
}
}

View File

@@ -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>