Thursday, February 3, 2011

ColdMVC: Number Tag

I've playing around with mobile web apps lately. ColdMVC has been a big help in getting them done quickly and "in the cloud".

I've been looking for a house since the market is so good right now and one thing I noticed when searching for houses online is the when you type in a price range only the keypad shows up on my phone. No letters. Just numbers. It's really nice. I viewed the source when I got back to my laptop and found out they were doing it with <input type="number" >. I decided to hack a ColdMVC tag together to hanlde this.

Here is how you call the tag...

<c:number name="miles" value="#service.miles()#">


Here is my hacked in logic...

<cfparam name="attributes.class" default="input"/>
<cfparam name="attributes.value" default=""/>
<cfif thisTag.executionMode eq "end">
<cfoutput>
<cfsavecontent variable="attributes.field">
<input type="number" name="#attributes.name#" title="#attributes.name#" value="#attributes.value#" class="#attributes.class#"/>
</cfsavecontent>
</cfoutput>

<cfset thisTag.generatedContent = coldmvc.form.field(argumentCollection=attributes) />
</cfif>


The above logic doesn't supporting binding, but it works to use. It would be cool if this tag was managed my ColdMVC HTMLHelper.cfc then I would have to worry about the attributes.

3 comments:

  1. You realize ColdMVC already has a number tag, right?

    http://www.coldmvc.com/tags/number

    ReplyDelete
  2. Shoot I missed that. You are correct. My fault. Thanks for the heads up, I will correct my tag.

    ReplyDelete
  3. Hah no problem. I like the your thought though. It definitely shows how easy ColdMVC is to extend.

    ReplyDelete