Make a button disabled:
this.att('disabled','disabled');
Get rid of the disabling:
this.removeAtt('disabled');
Make a button disabled:
this.att('disabled','disabled');
Get rid of the disabling:
this.removeAtt('disabled');
Jitendra wrote something cool which I assume is empowered by jquery.validate-vsdoc.js. It is:
$.validator.addMethod(
"compareDate",
function (value, element, comparewith) {
if (value != '')
var date1 = Globalize.parseDate(value, textBoxDateFormat).getTime();
if (comparewith != '')
var date2 = Globalize.parseDate(comparewith, textBoxDateFormat).getTime();
if (date1 != undefined && date2 != undefined)
return !(date1 > date2)
else
return false;
}
);
It is implemented in jQuery like so:
var firstShipDateField = $('#SiliconSampleDefinition_FirstShipDate');
var lastShipDateField = $('#SiliconSampleDefinition_LastShipDate');
if (firstShipDateField.val() == '') {
firstShipDateField.rules("remove");
} else {
firstShipDateField.rules("add", {
compareDate: lastShipDateField.val(),
messages: { compareDate: "I'm Angry!" }
});
}
On the C# side we will have:
@Html.CalendarFor(model => model.Foo.FirstShipDate, "/calendar.gif")
@Html.ValidationMessageFor(model => model.Foo.FirstShipDate)
The ValidationMessageFor will end up displaying "I'm Angry."
Two-thirds of the way down the page here is a how-to on The Remote Validator which is an MVC3 way to reach out to a C# method by way of AJAX to undertake complicated form field validations. We discussed using this for a problem today.
We have a class in our app called AccessMap that sort of looks like this:
using System;
using System.Collections.Generic;
using System.Reflection;
namespace OurApp.Core.Security
{
public class AccessMap
{
public List<string> Roles { get; set; }
public List<Guid> IdsOfTeamMemberAccounts { get; set; }
public List<Guid> IdsOfViewedAccounts { get; set; }
public AccessMap()
{
}
}
}
...only it has a lot more getsetters. 37 altogether. The getsetters are populated when the application spins up and then the AccessMap is referenced whenever relevant. If showing a list of "Team Member Accounts" and filtering down records shown by items permissioned to the user at hand, one may sanity check against the IdsOfTeamMemberAccounts in lieu of making a trip to the database. The AccessMap is cached in session.
The downside: lag when spinning up the app
The cure? I don't know. Perhaps we will populate portions of the AccessMap progressively as need be. Does anyone know a better way to approach this problem?