using #textField() but want to set a default value

270 views
Skip to first unread message

stofke

unread,
Apr 21, 2011, 5:44:42 AM4/21/11
to ColdFusion on Wheels
I used #textField()# to create a textfield but I want my textfield to
have a default value of my choice prefilled. Is that possible?

Andy Bellenie

unread,
Apr 21, 2011, 5:55:44 AM4/21/11
to cfwh...@googlegroups.com
You can use the defaultValue argument of the property() method in your model's init()
On 21 April 2011 10:44, stofke <kristof....@gmail.com> wrote:
I used #textField()# to create a textfield but I want my textfield to
have a default value of my choice prefilled.  Is that possible?

--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.


CG

unread,
Apr 8, 2012, 2:10:57 PM4/8/12
to cfwh...@googlegroups.com
I'm looking for the same solution, but I don't see how Andy's suggestion solves the problem. Possible that I'm misunderstanding the purpose of property(), but as I understand it this method is only used if you want to change the ORM mapping to the database. What I'm trying to do is set the default value of a text field when it initially loads (blank form). In the example below, "My Default Value" is what I want to be present in the text field on initial load.

<input type="text" name="mytextfield" value="My Default Value">

I've tried passing it through...
#textField(label="some label", property="db_field", objectName="obj_name", value="My Default Value")#

But wheels says it cannot pass it through because wheels sets that value.

I'm sure someone has addressed this. Seems pretty basic and wheels seems very well thought through. 

Thanks!

Chris


On Thursday, April 21, 2011 2:55:44 AM UTC-7, Andy Bellenie wrote:
You can use the defaultValue argument of the property() method in your model's init()
On 21 April 2011 10:44, stofke <email_stripped> wrote:
I used #textField()# to create a textfield but I want my textfield to
have a default value of my choice prefilled.  Is that possible?

--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+unsubscribe@googlegroups.com.

Per Djurner

unread,
Apr 8, 2012, 2:20:00 PM4/8/12
to cfwh...@googlegroups.com
I think Andy is correct, you should use the defaultValue argument on property().
Did you give it a try and it didn't work?

To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/WNh-zOXgcaQJ.

To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.

Chris Geirman

unread,
Apr 8, 2012, 8:38:11 PM4/8/12
to cfwh...@googlegroups.com
I apologize, I had not tried it and obviously did not understand how this works. Thanks Per for setting me straight... this was indeed the solution :)


On Sunday, April 8, 2012 11:20:00 AM UTC-7, Per Djurner wrote:
I think Andy is correct, you should use the defaultValue argument on property().
Did you give it a try and it didn't work?

jeffbourassa

unread,
Apr 9, 2012, 8:01:30 PM4/9/12
to ColdFusion on Wheels
Chris

Could you post the code for how you resolved this. I am running into
a similar issue, I have a ID field that I use across multiple forms, I
would like to set a default value - I have done the obvious in the
models init, however the default is not passing down to the text
fields with the same property name.

In my Admin.cfc model:

<cffunction name="init">
<!--- set default values for all forms - common fields --->
<cfset property(name="TeamID", defaultValue="#session.user.tID#")>

</cffunction>

In my forms:

#textField(objectName='teamhighlight', property='TeamID',
label='TeamID')#

When I view source I am getting no default value for the TeamID
textfield.


Any suggestions?


Jeff


On Apr 8, 5:38 pm, Chris Geirman <chris.geir...@gmail.com> wrote:
> I apologize, I had not tried it and obviously did not understand how this
> works. Thanks Per for setting me straight... this was indeed the solution :)
>
>
>
>
>
>
>
> On Sunday, April 8, 2012 11:20:00 AM UTC-7, Per Djurner wrote:
>
> > I think Andy is correct, you should use the defaultValue argument on
> > property().
> > Did you give it a try and it didn't work?
>
> > On Sun, Apr 8, 2012 at 8:10 PM, CG <email_stripped> wrote:
>
> >> I'm looking for the same solution, but I don't see how Andy's suggestion
> >> solves the problem. Possible that I'm misunderstanding the purpose of
> >> property(), but as I understand it this method is only used if you want to
> >> change the ORM mapping to the database. What I'm trying to do is set the
> >> default value of a text field when it initially loads (blank form). In the
> >> example below, "My Default Value" is what I want to be present in the text
> >> field on initial load.
>
> >> <input type="text" name="mytextfield" *value="My Default Value"*>
>
> >> I've tried passing it through...
> >> #textField(label="some label", property="db_field", objectName="obj_name",
> >> * value="My Default Value*")#
>
> >> But wheels says it cannot pass it through because wheels sets that value.
>
> >> I'm sure someone has addressed this. Seems pretty basic and wheels seems
> >> very well thought through.
>
> >> Thanks!
>
> >> Chris
>
> >> On Thursday, April 21, 2011 2:55:44 AM UTC-7, Andy Bellenie wrote:
>
> >>> You can use the defaultValue argument of the property() method in your
> >>> model's init()
> >>>http://cfwheels.org/docs/1-1/**function/property<http://cfwheels.org/docs/1-1/function/property>
>
> >>> On 21 April 2011 10:44, stofke <email_stripped> wrote:
>
> >>>> I used #textField()# to create a textfield but I want my textfield to
> >>>> have a default value of my choice prefilled.  Is that possible?
>
> >>>> --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "ColdFusion on Wheels" group.
> >>>> To post to this group, send email to cfwh...@googlegroups.com.
> >>>> To unsubscribe from this group, send email to cfwheels+unsubscribe@**
> >>>> googlegroups.com <cfwheels%2Bunsu...@googlegroups.com>.
> >>>> For more options, visit this group athttp://groups.google.com/**
> >>>> group/cfwheels?hl=en <http://groups.google.com/group/cfwheels?hl=en>.
>
> >>>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "ColdFusion on Wheels" group.
> >> To view this discussion on the web visit
> >>https://groups.google.com/d/msg/cfwheels/-/WNh-zOXgcaQJ.
> >> To post to this group, send email to cfwh...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> cfwheels+u...@googlegroups.com.

Andy Bellenie

unread,
Apr 10, 2012, 5:12:08 AM4/10/12
to cfwh...@googlegroups.com
You can't use session variables in your model init() like that because it is cached. You should pass in the session variable from your controller instead

<cfset foo = model("foo").new(teamId=session.user.tId)>

As a general rule you should avoid using session, request and app variables inside models.

Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages