I have this input on the view:
<%= Html.TextBoxCurrentDateWithoutPermission("EffectiveDate", Model.EffectiveDate.HasValue ? Model.EffectiveDate.Value.ToString("dd-MMM-yyyy") : "", new string[] { PERMISSIONS.hasICAdvanced }, new { @class = "economicTextBox", propertyName = "EffectiveDate", onchange = "parseAndSetDt(this); ", dataType = "Date" })%>
Here is the custom HTML Helper:
public static MvcHtmlString TextBoxCurrentDateWithoutPermission(
this HtmlHelper htmlHelper,
string name,
object value,
string[] permissions,
object htmlAttributes
)
{
foreach (string permission in permissions)
{
if (Chatham.Web.UI.Extranet.SessionManager.DisplayUser.IsInRole(permission))
{
// the user has the permission => render the textbox
return htmlHelper.TextBox(name, value, htmlAttributes);
}
}
// the user has no permission => render a readonly checkbox
var mergedHtmlAttributes = new RouteValueDictionary(htmlAttributes);
mergedHtmlAttributes["disabled"] = "disabled";
return htmlHelper.TextBox(name, value == "" ? DateTime.Now : value, mergedHtmlAttributes);
}
The way this works now is, when a user does NOT have the permission passed in, the box is disabled.
The way it needs to be -- if the user does NOT have the permission passed in, it needs to be enabled, however the only dates it can accept are todays date AND dates in the future.
So I need JQuery validation (or just plain JS), for this textbox on the page for the following case:
If the textbox is enabled AND the user does not have the permission, allow the user to input the current date or future dates ONLY.