Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfinput validation question

Participant ,
Nov 03, 2008 Nov 03, 2008
I am using the following to validate my data :

<cfinput type="text" name="unitValue#gfmPartNumberID#" value="#qryView.unitValue#" required="Yes" validate="float" message="Unit Value must be entered and must be numeric.">
<input type="hidden" name="gfmPartNumberID" value="#qryView.gfmPartNumberID#">

If I use validate=integer, it will not take decimals. If I use validate=float, it will take decimal input such as 19.99 but when I display, the outptu is 19.00 only. Can cfinput validate decimal inputs ?

If not, can I use javascript to validate if my field name is unitValue#gfmPartNumberID# ? I am using this to distinguish between different records.

Thanks
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2008 Nov 03, 2008
> I display, the outptu is
> 19.00 only. Can cfinput validate decimal inputs ?

*input* validation has no bearing whatsoever on what gets output once you
submit the form. If the user types in 19.99, then 19.99 will be what is
passed to the action page. If your output is outputting something else,
then it's the output that is the problem.

Post your code.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 04, 2008 Nov 04, 2008
I just use #dollarformat(unitValue)# to display the output with the dollar sign and it just puts 00 after the decimal.

When I insert into the table, I use this line :
<cfset col4 = listgetat(form.unitValue, i)>
which is inside a loop.

When I check the table contents, it is stored rounded up. For example, if I enter 346.88 in the form, the table has it stored as 347, thus my output with dollarformat is $347.00. The table is in sql server and the field is defined as datatype decimal, length 9.

So you are right, the output is displaying correctly. Now the next question is how do I insert into the table exaclty what is entered on the screen ? If 346.88 is entered, I want that stored and displayed as $346.88.

Thanks
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2008 Nov 03, 2008
quote:

Originally posted by: trojnfn
If not, can I use javascript to validate if my field name is unitValue#gfmPartNumberID# ? I am using this to distinguish between different records.

Thanks

You shouldn't have to.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2008 Nov 04, 2008
For example, if I enter 346.88 in the form, the table has it stored
as 347, thus my output with dollarformat is $347.00. The table is
in sql server and the field is defined as datatype decimal, length 9.


Test with:

<cfparam name="form.unitValue" default="346.88">
<cfoutput>#dollarFormat(form.unitValue)#</cfoutput>

You should get $346.88, as expected. So, the rounding off is happening at the database server.

You should use a second parameter('scale') for the decimal datatype, for example, decimal(9,2). If you omit the scale, and use, for example, decimal(9), SQL Server will use a default scale of 0 and the data will effectively be stored as an integer.



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 10, 2008 Nov 10, 2008
I changed the data type in the sql server to float, and now it stores the decimal and displays properly.

However, by making this chagne, I solved one problem but seem to have created another. When I attempt to update, I use set unitValue = '#Evaluate("form.unitValue#gfmPartNumberID#")#'

But it blows up and says something about cannot evaluate. Before I chagned the data type to float, it was set at int and the update worked but it did not save the decimals.

Now I have the decimals but the update does not work because of float. What do I need to do to keep the decimals and to get the update to work ?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 10, 2008 Nov 10, 2008
LATEST
you didn't change the gfmPartNumberID field to float, did you?
only the field that stores the unitValue value should be
FLOAT/DOUBLE/DECIMAL

and no need for that cumbersome Evaluate() - just use array notation:
unitValue = <cfqueryparam cfsqltype="cf_sql_float" scale="2"
value="#form["unitValue" & gfmPartNumberID]#">

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2008 Nov 10, 2008
I use set unitValue = '#Evaluate("form.unitValue#gfmPartNumberID#")#'

There is no need for the complexity. This should do it:

<cfset unitValueField = "unitValue" & gfmPartNumberID>
<cfset unitValue = form[unitValueField]>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources