Thursday, December 1, 2011

apply the disabled attribute via jQuery

Make a button disabled:

this.att('disabled','disabled');

 
 

Get rid of the disabling:

this.removeAtt('disabled');

jquery.validate and .rules

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."

The Remote Validator in MVC3

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.

Security

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?

Wijmo mistake

http://wijmo.com/ is made by ComponentOne and not Telerik. I was mistaken.

backing store

A backing store is a control that will be submitted in a form. A backing store may be a hidden field or a field invisible by way of CSS or a control that masquerades as just one piece of a set of controls. Different controls take in user data, then jQuery/JavaScript update the backing store where the collected data will ultimately be submitted from.

Wijmo Telerik Controls

...are apparently build on jQuery UI controls. (so I hear)

 

Update! This posting is a mistake, yet it keeps getting traffic. Please see: http://tom-jaeschke.blogspot.com/2011/12/wijmo-mistake.html