Hi Patrick,
Thanks for the info. I actually figured it out for myself by digging
through the abstractRecord.cfc and noticed the _getObjectMetaData
method. I ended up doing something like this:
projDetail._getObjectMetadata().getField("Technical_Guidance").length
which works really well, although I am not sure if this is best
practice?!
If anyone is interested, I am using this to set a maxlength on a
textarea using a bit of jquery to pick up the above length which I
place in the title attribute of the textarea tag. It works for all
textarea tags on a page.
e.g.:
<div class="optional">
<label for="ProfAdv_Variations">Non-conformance:</label>
<textarea name="ProfAdv_Variations" id="ProfAdv_Variations"
class="inputTextarea" rows="5" cols="21"
title
=
"#projDetail
._getObjectMetadata
().getField
("ProfAdv_Variations").length#">#projDetail.getProfAdv_Variations()#</
textarea>
</div>
I then call limitChars() using the following on my form page:
// Add this to the $(document).ready(function() {});
$(function(){
$('textarea').focus(function(){
limitChars($(this).attr("id"), $(this).attr("title"), $
(this).next("div").attr("id"),'limiterror');
}).keyup(function(){
limitChars($(this).attr("id"), $(this).attr("title"), $
(this).next("div").attr("id"),'limiterror');
});
The limitChars function is:
/*
Modified by Dave Phipps (added errorclass argument and building
infodiv on the fly)
from original code by Anis uddin Ahmad
(http://www.ajaxray.com/blog/2007/11/09/interactive-character-limit-for-textarea-using-jquery/
)
*/
function limitChars(textid, limit, infodiv, errorclass) {
var text = $('#'+textid).val();var textlength = text.length;
var textlength = text.length;
//if the limitdiv is undefined then add it
if(infodiv == undefined) {
var taid = $('#'+textid).attr("id");
var divname = taid+'_limit';
$('#'+textid).after('<div id="'+ divname +'"></div>')
infodiv = divname;
}
if(textlength > limit) {
$('#' + infodiv).html('You cannot write more than '+limit+'
characters!').addClass(errorclass);
$('#'+textid).val(text.substr(0,limit));
return false;
} else {
$('#' + infodiv).html('You have '+ (limit - textlength) +'
characters left.').removeClass(errorclass);
return true;
}
}
Cheers,
Dave
On 9 Jul 2008, at 00:36, Patrick Branley wrote:
Hi Dave
I had a bit of trouble getting meta data working myself. This is the
syntax
I ended up using. The key was using xmlRoot.
<cfset obj = Reactor.createRecord("customerProfile") />
<cfset nameMaxLen =
obj
._getDictionary
().getValue("xmlRoot.customerprofile.firstname.maxlength")
/>
From my understanding you pay the hit of generating the XML in
_getDictionary() once, but after that its cached in the object.
As for validate. When I get some spare time ill try to blog how I do
validations. The best way I found on learning how to do it was to
read the
code in Model-Glue for GenericCommmit events.
I spent some time myself trying to work out if I should use reactor or
transfer, but in the end the killer feature for me was this whole
metadata
stuff and being able to get the maxlength from the database etc.
without
having to code that into my config xml files. I understand in
transfer you
have to create all this stuff yourself in the XML config.
Pat
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
] On
Behalf Of David Phipps
Sent: Wednesday, 9 July 2008 2:50 AM
To: [email protected]
Subject: [Reactor for CF] Accessing the metadata
Hi,
I can't seem to workout how to access the metadata for an object? What
I have is some textareas in a form that I need to know what the
maxlength is so I can do some jquery to limit the input.
I noticed in the project_dateMetadata.cfc is the variable that I need:
<cfset variables.metadata.fields[12]["length"] = "255" /> but how do I
access it from the record object or do I need to create a metadata
object on the project_data table? I have looked in abstractRecord and
I can see a _getObjectMetadata method, but will this give me the right
data and should I use it?
Also, does anyone have any links to an article/docs about using
validate().
One final thing, which I know is mentioned quite a lot, is Reactor
still being developed/complete/losing out to Transfer? Whenever, I
look at Transfer it seems overly complicated - maybe I just haven't
spent enough time reading about it, but I prefer Reactor and would
hate to see it fade away.
Cheers,
Dave
_______________________________________________________________________
David Phipps
Director, Chapel Studios
T +44 (0)20 7100 6980 F +44 (0)20 7100 6981 M +44 (0)7765 240899
New Broad Street House, 35 New Broad Street, London, EC2M 1NH, UK
http://www.chapel-studios.co.uk
_______________________________________________________________________
The Chapel Studios group of companies are registered in England.
'Chapel Studios' and the Chapel Studios logo are registered trademarks
of Chapel Studios. The information in this email is confidential,
intended solely for the addressee, and may be legally privileged. If
you are not the addressee or authorized to receive this for the
addressee, you must not use, copy, disclose or take any action based
upon this message or any information herein. If you have received
this message in error, please advise the sender immediately by reply
e-
mail.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
-- --
Reactor for ColdFusion Mailing List
[EMAIL PROTECTED]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
-- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- --
Reactor for ColdFusion Mailing List
[EMAIL PROTECTED]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- --
_______________________________________________________________________
David Phipps
Director, Chapel Studios
T +44 (0)20 7100 6980 F +44 (0)20 7100 6981 M +44 (0)7765 240899
New Broad Street House, 35 New Broad Street, London, EC2M 1NH, UK
http://www.chapel-studios.co.uk
_______________________________________________________________________
The Chapel Studios group of companies are registered in England.
'Chapel Studios' and the Chapel Studios logo are registered trademarks
of Chapel Studios. The information in this email is confidential,
intended solely for the addressee, and may be legally privileged. If
you are not the addressee or authorized to receive this for the
addressee, you must not use, copy, disclose or take any action based
upon this message or any information herein. If you have received
this message in error, please advise the sender immediately by reply e-
mail.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[EMAIL PROTECTED]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --