ValidateThis / cfUniform integrations

31 views
Skip to first unread message

Jim Priest

unread,
Jul 19, 2012, 9:35:08 AM7/19/12
to cfunifo...@googlegroups.com
Is there a sample app or documentation about the VT hooks in cfUniform.

In form.cfm:

7/12/10            Added integration support for ValidateThis (http://www.validatethis.org/).        MQ
                        added the 'VT', 'VTcontext', 'VTtarget', and 'VTlocale' attributes

I've got it wired up following the instructions at the ValidateThis site - and things are working but I was wondering if there were any benefits to using these 'VT' attributes.

Thanks!
Jim

Matt Quackenbush

unread,
Jul 19, 2012, 10:08:36 AM7/19/12
to cfunifo...@googlegroups.com
Hmm. I'm not sure, to be honest. Let me poke around and see if I have anything already written up. (I'm not sure that the docs/demos section of quackfuzed.com is actually up to date.)  In the meantime, here is an example from a project that has been in production for a couple of years...

    <uform:form action="#event.linkTo(xit_TicketListingSubmit)#"
                id="ticket-listing-form"
                errors="#ticketListing.getErrors()#"
                errorMessagePlacement="both"
                submitValue=" Save "
                loadjQuery="false"
                loadValidation="true"
                loadDateUI="true"
                loadTimeUI="true"
                VT="#VT#"
                VTtarget="#ticketListing#"
                VTcontext="New">

#VT# is a reference to ValidateThis after instantiation (duh).

#ticketListing# is a reference to the object that the form is representative of.

Whether or not "there [are] any benefits to using these 'VT' attributes" is pretty much a subjective matter. I personally love it, because I don't have to worry about any of the VT stuff in my views. Just pass the values to cfUniForm, and it adds the VT stuff for me. That said, I don't think I'd spend the time to go back to old code and change it. :-)




Jim

--
You received this message because you are subscribed to the Google Groups "cfUniForm-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cfuniform-users/-/qBFDkdkAr6YJ.
To post to this group, send email to cfunifo...@googlegroups.com.
To unsubscribe from this group, send email to cfuniform-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfuniform-users?hl=en.

Jim Priest

unread,
Jul 19, 2012, 10:39:44 AM7/19/12
to cfunifo...@googlegroups.com
I'm all about less typing :)  

So currently I'm loading up the following on my views (FW/1)

* rc.config.cfUniFormConfig
* rc.validator.getRequiredFields(objectType='Document',context='add') 
* <cfimport prefix="uform" taglib="/common/frameworks/cfuniform/tags/forms/cfUniForm/" />
* rc.Validator.getInitializationScript(JSIncludes=false)
* rc.Validator.getValidationScript( objectType="Document", context="add" )

If I use the VT attributes - what can I eliminate? 

Thanks!
Jim

Matt Quackenbush

unread,
Jul 19, 2012, 10:45:19 AM7/19/12
to cfunifo...@googlegroups.com
All of the rc.validator lines would disappear. The only two VT attributes you'd need are VT and VTtarget.  VTcontext is optional, and only useful if you are using contexts in your VT definitions.


--
You received this message because you are subscribed to the Google Groups "cfUniForm-users" group.

Jim Priest

unread,
Jul 19, 2012, 11:00:23 AM7/19/12
to cfunifo...@googlegroups.com
Cool.  Now I just need to figure out how to pass that info with FW/1 :)

Jim

Matt Quackenbush

unread,
Jul 19, 2012, 11:04:09 AM7/19/12
to cfunifo...@googlegroups.com
Whatcha mean?  I am assuming that `rc.validator` is a reference to VT. So just use that in the VT attribute of your form setup. The only other required item would be the object that VT is to generate validations for, passed to the VTtarget attribute.  Just add that to the `rc` (if you don't already have it) and voila!

Did I miss something?  (Probably!)

Jim Priest

unread,
Jul 19, 2012, 11:18:17 AM7/19/12
to cfunifo...@googlegroups.com
This is my first FW/1 app so bear with me...

In my Document controller I've got:

rc.document = variables.DocumentService.newDocument();
rc.validator = variables.DocumentService.getValidator( document = rc.document );

And in my document view form I added:

<uform:form
action="#buildURL( 'security.login' )#"
attributecollection="#local.cfUniFormConfig#"
id="frmMain"
submitValue="Login"
VT="#rc.validator#"
VTtarget="#rc.document#"
VTcontext="add"
VTlocale="en_US">

It complained about a locale and I added:  VTlocale="en_US"

And the form renders but I got no JS/required fields :(

Thanks!
Jim

Matt Quackenbush

unread,
Jul 19, 2012, 11:28:09 AM7/19/12
to cfunifo...@googlegroups.com
What does the "required fields" part of your "JS/required fields" comment mean?  I am assuming that you're saying that none of the VT JS is being rendered?

Jim Priest

unread,
Jul 19, 2012, 11:55:16 AM7/19/12
to cfunifo...@googlegroups.com
Yep - form renders but non of the validation, required field checks work - ie no JS.

Jim

Matt Quackenbush

unread,
Jul 19, 2012, 12:27:18 PM7/19/12
to cfunifo...@googlegroups.com
Hmm. That shouldn't happen. :-)   Let me look and see if there is something that I missed. In the meantime, I am thinking that maybe you should just keep on with what works, so as not to waste time spinning your wheels.  (I am piled under at the moment, and don't have time to dig into it too deeply, unfortunately.)

Matt Quackenbush

unread,
Jul 19, 2012, 12:59:48 PM7/19/12
to cfunifo...@googlegroups.com
What does your cfUniFormConfig look like?  You don't by chance have validation loading turned off, do you?  That is the only glaring difference I can see (you're using a config bean/struct, and I'm not).

Jim Priest

unread,
Jul 19, 2012, 2:34:55 PM7/19/12
to cfunifo...@googlegroups.com
On Thu, Jul 19, 2012 at 12:59 PM, Matt Quackenbush <quack...@gmail.com> wrote:
What does your cfUniFormConfig look like?  You don't by chance have validation loading turned off, do you?  That is the only glaring difference I can see (you're using a config bean/struct, and I'm not).

, cfUniFormConfig = {
commonassetsPath = "/common/frameworks/cfuniform/commonassets/"
, loadDateUI="false"
, loadjQuery="false"
, loadMaskUI="false"
, loadTextareaResize="false"
, loadTimeUI="false"
         , loadValidation="false"

Ding Ding!  So I need to do loadValidation = true?


Matt Quackenbush

unread,
Jul 19, 2012, 2:54:14 PM7/19/12
to cfunifo...@googlegroups.com
Ayep. Now that I think about it a bit more, I remember that being one of the other issues that I ran into when doing things separately (e.g. I was running into some conflicts). So combining them and telling cfUniForm to load validations AND give it the VT stuff allows it to handle everything in one neat package.

So, turning on loadValidation should fix you up. Let me know!


Jim Priest

unread,
Aug 1, 2012, 3:15:16 PM8/1/12
to cfunifo...@googlegroups.com
I finally got back to this - it 'almost' seems to work.  :\

When my code renders I get a nasty JS error...


Which points to the generated script...  Line 22:
<link href="/common/frameworks/cfuniform/commonassets/css/uni-form.css" type="text/css" rel="stylesheet" media="all" /><!--[if lte ie 8]><link href="/common/frameworks/cfuniform/commonassets/css/uni-form-ie.css" type="text/css" rel="stylesheet" media="all" /><![endif]--><link href="/common/frameworks/cfuniform/commonassets/css/uni-form.default.css" type="text/css" rel="stylesheet" media="all" /> <script src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js" type="text/javascript"></script><script src="/common/frameworks/cfuniform/commonassets/scripts/jQuery/forms/jquery.field-0.9.3.min.js" type="text/javascript"></script> <script type="text/javascript">/*<![CDATA[*/jQuery(function($){$.validator.addMethod("nohtml",function(v,e,o){var m = v.search("</?\\w+((\\s+\\w+(\\s*=\\s*(?:\\\".*?\\\"|'.*?'|[^'\\\">\\s]+))?)+\\s*|\\s*)/?>");return m===-1;},$.format("value cannot contain any HTML tags.")); $.validator.addMethod("regex",function(v,e,p){if(v===''){return true};return v.match(p);},$.format("The value entered does not match the specified pattern ({0})")); $.validator.addMethod("equalto",function(v,e,p){var $parentForm = $(e).closest("form");var $compareto = $(p,$parentForm);var target = $compareto.unbind(".validate-equalTo").bind("blur.validate-equalTo",function(){$(e).valid();});return v==target.getValue();},$.format("The value cannot not contain the value of another property.")); $.validator.addMethod("true",function(v,e,o){if(v===''){return true;}var re = /^([1-9]|true|yes)$/i;return re.test(v);},$.format("The value entered must be a true boolean.")); $.validator.addMethod("time",function(v,e,p){return this.optional(e)||/^([01][0-9])|(2[0123]):([0-5])([0-9])$/.test(v);},$.format("The value must be a valid time.")); $.validator.addMethod("notregex",function(v,e,p){if(v===''){return true};return !v.match(p);},$.format("The value entered does not match the specified pattern ({0})")); $.validator.addMethod("boolean",function(v,e,o){if(v===''){return true;}var re = /^((-){0,1}[0-9]{1,}(\.([0-9]{1,})){0,1}|true|false|yes|no)$/i;return re.test(v);},$.format("The value entered must be a boolean")); $.validator.addMethod("minpatternsmatch",function(v,e,o){var minMatches = 1;var complexity = 0;if(!v.length){return true;}if(o.minMatches){minMatches = o.minMatches;}var re = /^pattern_/i;for(var key in o){if(re.test(key)&&v.match(o[key])){complexity++;if(complexity===minMatches){return true;}}}return complexity>=minMatches;},$.format("Value did not match the pattern requirements.")); $.validator.addMethod("pastdate",function(v,e,o){if(v===''){return true;}var dBefore = new Date();dBefore = new Date(dBefore.toDateString());var dValue = new Date(v);var ok = !/Invalid|NaN/.test(dValue);if(o.before){dBefore = new Date(o.before);}if (ok){ok=dBefore>dValue}return ok;} ,$.format("The date entered must be in the past.")); $.validator.addMethod("inlist",function(v,e,o){if(v===''){return true;}var delim = o.delim ? o.delim : ",";var lst = o.list.split(delim);var ok = false;$.each(lst, function(i,el){if (v.toLowerCase()==el.toLowerCase()){ok=true;return false;}});return ok;},$.format("value was not found in list.")); $.validator.addMethod("notinlist",function(v,e,o){var delim = o.delim ? o.delim : ",";var lst = o.list.split(delim);var ok = true;$.each(lst, function(i,el){if (v.toLowerCase()===el.toLowerCase()){ok=false;return false;}});return ok;},$.format("Value was found in list.")); $.validator.addMethod("doesnotcontainotherproperties",function(v,e,o){var ok=true;var $form=$(e).closest("form");$(o).each(function(){var propertyValue = $(':input[name='+this+']',$form).getValue();if(propertyValue.length){if(propertyValue.search(",")){propertyValue = propertyValue.split(",");}$(propertyValue).each(function(){var test = v.toString().toLowerCase().search(this.toString().toLowerCase())===-1;if (!test){ ok = false;}});}return ok;});return ok;},$.format("The value cannot not contain the value of another property.")); $.validator.addMethod("false",function(v,e,o){ if (v===''){return true;}var re = /^(0|false|no)$/i;return re.test(v);},$.format("The value entered must be a false boolean.")); $.validator.addMethod("daterange",function(v,e,o){if (v==='') return true;var thedate = new Date(v);var ok = !/Invalid|NaN/.test(thedate);var start = new Date();var end = new Date();if(ok){if(o.from){start=new Date(o.from);}if(o.until){var end=new Date(o.until);}if(start!==end){ok=((start<=thedate)&&(thedate<=end));}}return ok;},$.format("The date entered must be in the range specified.")); $.validator.addMethod("futuredate",function(v,e,o){ if(v===''){return true;}var dToday = new Date();var dValue = new Date(v);if(o.after){dToday = new Date(o.after);}return (dToday<dValue);},$.format("The date entered must be in the future.")); });/*]]>*/</script><script src="/common/frameworks/cfuniform/commonassets/scripts/jQuery/forms/uni-form.jquery.js" type="text/javascript"></script> <script type="text/javascript">jQuery(document).ready(function() {<script type="text/javascript">/*<![CDATA[*/jQuery(function($){var $form_frmMain = $("#frmMain");$form_frmMain.validate({ignore:'.ignore'}); var fm={}; fm['categoryName'] = $(":input[name='categoryName']",$form_frmMain); if(fm['categoryName'].length){fm['categoryName'].rules("add",{required:true,messages:{required:"The category name is required."}});} fm['categoryName'] = $(":input[name='categoryName']",$form_frmMain); fm['categoryName'] = $(":input[name='categoryName']",$form_frmMain); if(fm['categoryName'].length){fm['categoryName'].rules('add',{"maxlength":5,"messages":{"maxlength":"The category name must be no more than 5 characters long."}});} });/*]]>*/</script> jQuery('#frmMain').validate(); });</script></head>

You can see above the unnested </script> tags which may be part of the issue... 
 
Jim

Jim Priest

unread,
Aug 1, 2012, 3:53:01 PM8/1/12
to cfunifo...@googlegroups.com
I tried to track this down via form.cfm but quickly got lost. 

If you dump out the jsConfig however you'll see the extra </script> tag get added - around line 722...



On Wednesday, August 1, 2012 3:15:16 PM UTC-4, Jim Priest wrote:
I finally got back to this - it 'almost' seems to work.  :\

When my code renders I get a nasty JS error...


Which points to the generated script...  Line 22:

Matt Quackenbush

unread,
Aug 6, 2012, 11:06:02 AM8/6/12
to cfunifo...@googlegroups.com
Jim,

What version of VT are you utilizing?  I don't have this issue locally or on the one production site that I have which uses these integrations. I'm betting there is something different which is causing the regex to not function as intended.


--
You received this message because you are subscribed to the Google Groups "cfUniForm-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cfuniform-users/-/EacfV__J9pMJ.

Jim Priest

unread,
Aug 6, 2012, 11:17:15 AM8/6/12
to cfunifo...@googlegroups.com
No, no, no.  *MY* code is fine.  Your's is obviously broken :)

Hmm -  I believe I'm running QuackFuzed-cfUniForm-v4.6.0-11-g95c6413  

I am running a newer version of jQuery (not the one included in the download), and the latest CF9  ( Version 9,0,1,274733 )

Jim

Matt Quackenbush

unread,
Aug 6, 2012, 11:34:39 AM8/6/12
to cfunifo...@googlegroups.com
Right. I'm wondering what **VT** version you're on. I suspect therein lies the difference (e.g. my regex is for an older version 0.98?).

Jim Priest

unread,
Aug 6, 2012, 11:51:11 AM8/6/12
to cfunifo...@googlegroups.com
That's be it... I'm using VT 1.2

Jim

Matt Quackenbush

unread,
Aug 6, 2012, 12:21:02 PM8/6/12
to cfunifo...@googlegroups.com
Okie dokie. I will check into it as soon as I can. In a couple of hours I'm headed out of town for the week, so it'll probably be next week before I have a chance to look into it.  That probably doesn't help you much right now, though.  :-(


Jim Priest

unread,
Aug 6, 2012, 12:34:21 PM8/6/12
to cfunifo...@googlegroups.com
Get outta town!  :)  As long as we've identified what the issue is I'm good.  

I can roll back to VT .98 for the time being.  This app won't be done for awhile :)

Thanks!
Jim

Matt Quackenbush

unread,
Aug 18, 2012, 9:59:16 PM8/18/12
to cfunifo...@googlegroups.com
Hey Jim,

Guess what problem I ran into a few minutes ago?  ;-)

See if the attached form.cfm doesn't do the trick for you with the latest VT.  It fixed the issue for me with VT 1.2.

Thanks!
form.cfm

Jim Priest

unread,
Aug 20, 2012, 9:31:20 AM8/20/12
to cfunifo...@googlegroups.com
Woot! This seems to work with a few caveats:

1) Element ATTRIBUTES.ERRORMESSAGEINLINEPLACEMENT is undefined in a
Java object of type class coldfusion.runtime.PageScope referenced as
''

I had to add errorMessageInlinePlacement = "top" (doesn't seem to pick
up default?)

2) Had to add VTlocale="EN_US" (reading the VT docs en_us is the
default so it might be useful to have cfUniform default to this as
well)??

<uform:form
action="#buildURL( 'security.login' )#"
attributecollection="#rc.config.cfUniFormConfig#"
id="frmMain"
requiredFields="#rc.validator.getRequiredFields(objectType='User',context='login')#"
VT="#rc.validator#"
VTtarget="#rc.user#"
VTcontext="login"
VTlocale="EN_US"
errorMessageInlinePlacement = "top"
submitValue="Login &raquo;">


Once I did that things seem to work.

I'm in the middle of refactoring some things to work in our production
environment so I have a few path / css / js issues but I don't see the
error I was originally getting. I should have that sorted out this
afternoon and I'll let you know if anything else crops up.

Jim

Matt Quackenbush

unread,
Aug 20, 2012, 9:46:25 AM8/20/12
to cfunifo...@googlegroups.com
1) Hmmm. Can't duplicate that one.

2) Ayep. Found that one after I emailed the other night. I actually solved it a different way, because I forgot about the damn attribute being in form.cfm. So I've "unfixed" my fix (adding it to my cfUniFormConfig bean) and added the default of en_US as you mentioned.

Note that I *have not* made these changes to the GitHub code yet. ;-)

Let me know what else you find!

Jim Priest

unread,
Nov 1, 2012, 1:20:28 PM11/1/12
to cfunifo...@googlegroups.com
Hey Matt,

Can you send me the latest version of your form.cfm?  I just looked and it doesn't look like you updated GIT lately.

I made some changes to my development environment and am running into this issue again.  I'm guessing I never committed your tweaked form.cfm to SVN :\

Thanks!
Jim

Matt Quackenbush

unread,
Nov 1, 2012, 1:25:55 PM11/1/12
to cfunifo...@googlegroups.com
Hmmm. Not sure the git status. I thought the develop branch was updated, but very well could have forgotten that! Anywho, see attached.



form.cfm

Jim Priest

unread,
Nov 1, 2012, 1:49:41 PM11/1/12
to cfunifo...@googlegroups.com
Thanks!!!

Unfortunately diffing that against what I have shows it's the same file.

I tweaked my local dev environment to have a D:\ drive using SUBST and everything 'seems' to work but I've got this odd JS rendering again.  

Out of curiosity what version of jQuery and jQuery UI are you using?

Everything *does* work fine on our staging server so I have to assume it's something with my local setup :(

Jim

Matt Quackenbush

unread,
Nov 1, 2012, 2:10:12 PM11/1/12
to cfunifo...@googlegroups.com
I don't have immediate access to anything using the latest stuff, but I _think_ 1.7.1 is the version being used for both jQuery and jQuery UI. Can't swear to it, though. :-(

Jim Priest

unread,
Nov 1, 2012, 6:16:27 PM11/1/12
to cfunifo...@googlegroups.com
So I back tracked all day and it turns out it was my VT version.

For some reason I thought I was running v1.2 which is where I originally ran into this cfUniform issue.  But at some point I rolled back to 0.99 as that's whats running in staging.

If I use your updated form.cfm and the latest VT however I still get the javascript error.

Jim

Matt Quackenbush

unread,
Nov 1, 2012, 6:22:12 PM11/1/12
to cfunifo...@googlegroups.com
Hmm. That's very odd. I am using that very version with VT 1.2 with no troubles.  Shit, it's VT 1.1 that I'm using it with. Apparently I'm still behind on VT, but I definitely can't play with it at this moment. Any chance you can give VT 1.1 a whirl?

Jim Priest

unread,
Nov 1, 2012, 7:28:25 PM11/1/12
to cfunifo...@googlegroups.com
I don't see an obvious 1.1 download on Github...

For now - it's working and that's all I care about...

Jim
Reply all
Reply to author
Forward
0 new messages