Hi Fernando,
Upon taking another look, I agree that this is somewhat confusing, but
it actually does work correctly.
If the event.copyToScope() function references a value that does not
exist in the event, it does indeed return an empty string, but it
*does not* create the value in the event. Therefore, the test for
event.exists("phraseError") will work as anticipated despite the use
of event.copyToScope().
This is actually true of the event.getValue() function as well -- it
will return an empty string if the value does not exist, but it does
not create the value within the event context unless you supply a
default as the second argument. That means that this:
event.getValue("phraseError")
And this:
event.getValue("phraseError", "")
Will both return empty strings (assuming the value does not exist),
but the latter form will create the "phraseError" value in the event,
while the former will not.
The key distinction here is that while the "phraseError" variable will
always exist in the variables scope, event.exists() is checking for
the presence of the value in the event itself.
Does that make sense?
--
Ezra Parker
On Thu, Feb 11, 2010 at 11:51 AM, Fernando Lopez <[email protected]> wrote:
> http://docs.model-glue.com/wiki/QuickStart/5:ValidatingaForm
>
>
> While going through the steps of the quickstart I found that the
> following is not correct
>
> ---------------------------------------------------------
> <cfset event.copyToScope( variables,
> "xe_translate,phrase,phraseError" ) />
> <cfset submit = event.linkTo( xe_translate ) />
>
> <cfform action="#submit#">
> <cfinput type="text" name="phrase" required="false"
> value="#phrase#" />
> <input type="submit" value="Ok" />
>
> <cfif event.exists("phraseError")>
> <cfoutput><p style="color: red;">#phraseError#</p></
> cfoutput>
> </cfif>
> </cfform>
> ---------------------------------------------------------
>
> By using copyToScope() wouldn't we create the "variables.phraseError"
> every time? it may have a blank value but it exists in the "variables"
> scope.
>
> so the <cfif event.exists("phraseError") > should be changed to
> something other than checking the existence of the "phraseError".
> Maybe the length of it would do the trick?
>
> We already know "variables.phraseError" will exist in the "variables"
> scope whether with a value from the controller or with blank from the
> initialization of it by using copyToScope().
>
> could somebody change that conditional to <cfif
> len(variables.phraseError) neq 0 > ?
>
> This may help new developers going through the steps in the tutorials.
>
> Fernando
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
>
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en