Forums

Translate "Must be a number!"

mackirony 05 Jul, 2010
Hi there, it's been a while ;-)

My problem:

I have some fields that are not required but have to contain a number.
My site is in Dutch and when I enter letters in the feeld and click the submit button the error message reads "Must be a number!"

I tried entering the error message in the title-attribute like this:
<input class="cf_inputbox validate-digits" maxlength="12" size="12" id="prijs_van" name="prijs_van" type="text" title="Is geen getal" />

...but this doesn't work as it does with fields that are required

I also tried the multilanguage plugin (I have used that succesfuly on other sites) but that doesn't work on that phrase.

Any idea how I can get "Must be a number!" translated? It is the only thing on the form that is still in english. :?
GreyHead 05 Jul, 2010
Hi mackirony ,

You can do it more or less by switching to "Show my Own Div" messages instead of the default ones
<input class="cf_inputbox required validate-digits" maxlength="12" size="12" id="prijs_van" name="prijs_van" type="text" title="Is geen getal" />
<div id='CF_LV_ERROR_prijs_van' style='display:none;' >Een aantal is vereist</div>


Bob
mackirony 06 Jul, 2010
Thanks Bob, for your fast reply...again ;-)

Bummer. I managed to make a nice form without the "Show My Own DIV" feature. At least I made 5 forms for this website, some of them rather large. This means I have to ad a DIV to all fields (witch is quiet a task) just to have that little phrase translated. I was kinda hoping for a faster solution. :wink:
GreyHead 06 Jul, 2010
Hi mackirony,

I agree - I'm surprised it doesn't work. If I have time later I'll go dig in the code and see if I can find an easier fix.

Bob
mackirony 06 Jul, 2010
Apparently I'm not the one handing over easy issues to you.

I made an email field not required but with "validate-email" in the class. Here the message in the "title" attribute is shown when submitted is not an email. I was expecting that it was an issue with fields that need validation but are not required but this doesn't seem the case.

An other weird thing I figured out is that the message "Must be a number!" is in the file livevalidation_standalone.js while the messages "This field is required" and "Please enter a valid email address. For example fred@'+'domain.com" are in jsvalidation2.js.

Not sure but think I found a bug. 😶
GreyHead 06 Jul, 2010
Hi mackirony,

Indeed I think you have found a bug.

Try switching to validate-number instead. Looking at the code I suspect that the validation is identical and the 'title' error message works.

Bob
mackirony 07 Jul, 2010
No the validation is not identical. It accepts dots with is even better for my forms and indeed this works.

I was aware of the "validate_number" option and I'm puzzled why I didn't try this yesterday. One small comment on this type of validation. I think it should accept comma's also.

Could be there is a standard validation method for numbers with digits after a comma that I'm not aware of.

Anyway, solved my little problem.

Thanks Bob.
ultima 05 Sep, 2010
As I needed both the validate-number and validate-digits check I fixed it by changing 2 files:


1. Jsvalidation2.js (change starts at line 100)
		if ( ['text', 'password'].contains(type) ) {	
			if(field.hasClass('validate-number')){
				if( tmessage) { var message_validate_number = tmessage; }
				name.add( Validate.Numericality, { 
					notANumberMessage: message_validate_number,
					onlyInteger: false 
				});
				fieldsarray[fieldsarray_count] = name;
				fieldsarray_count = fieldsarray_count + 1;
			}
			if(field.hasClass('validate-digits')){
				if( tmessage) { var message_validate_digits = tmessage; }
				name.add( Validate.Numericality, { 
					notAnIntegerMessage: message_validate_digits, 
					onlyInteger: true 
				});
				fieldsarray[fieldsarray_count] = name;
				fieldsarray_count = fieldsarray_count + 1;

2. Livevalidation_standalone.js (change starts at line 632)
        if ((!isFinite(value)) && (onlyInteger==false)) Validate.fail(notANumberMessage);
        if ((onlyInteger==true) && (!isFinite(value) ||(/\.0+$|\.$/.test(String(suppliedValue))))) Validate.fail(notAnIntegerMessage);

Tested it with both a number and a digits field. A character is not accepted in both fields, a number with decimals only in the validate-digits field and a number in both the validate-number and validate-digits field.
This topic is locked and no more replies can be posted.