Merge pull request #296 from halkyon/old_js_validation_remnants

MINOR Removing old client side validation remains - NumericField.js
This commit is contained in:
Ingo Schommer 2012-04-11 06:15:25 -07:00
commit 5ea080a585
2 changed files with 1 additions and 68 deletions

View File

@ -7,13 +7,6 @@
*/
class NumericField extends TextField{
function Field() {
$html = parent::Field();
Requirements::javascript(SAPPHIRE_DIR . 'javascript/NumericField.js');
return $html;
}
function Type() {
return 'numeric text';
}

View File

@ -1,60 +0,0 @@
NumericField = Class.create();
NumericField.applyTo('input.numeric');
NumericField.prototype = {
initialize: function() {
this.oldValue = this.value;
},
setRange: function( minValue, maxValue ) {
this.minValue = minValue;
this.maxValue = maxValue;
},
onkeyup: function() {
var testValue = this.value;
if( testValue == this.oldValue )
return;
var length = this.maxLength;
this.value = '';
var testedOk = true;
var regex = new RegExp( '^\\d{0,' + length + '}$' );
// check that the value is numeric
if( !testValue.match( regex ) )
testedOk = false;
if( testedOk && testValue.length > 0 ) {
// check that the number is not outside the range
if( testedOk && typeof this.minValue != 'undefined' && parseInt(testValue) < this.minValue )
testedOk = false;
if( testedOk && typeof this.maxValue != 'undefined' && parseInt(testValue) > this.maxValue )
testedOk = false;
// use any external tests
if( testedOk && typeof this.externalValidate != 'undefined' && !this.externalValidate( testValue ) )
testedOk = false;
}
if( testedOk ) {
this.oldValue = this.value = testValue;
// DEBUG This produces weird javascript-errors, and is not very useable at all
// DONT MERGE
/*
if( this.value.length == this.maxLength && this.nextField )
this.nextField.focus();
*/
if( this.callOnValidate )
this.callOnValidate();
} else
this.value = this.oldValue;
}
}