mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE Moved GSTNumberField from sapphire/forms to new 'formfields_nz' module
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97475 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ade94cbc3f
commit
a138615a96
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Field for displaying NZ GST numbers (usually 8-9 digits in the format ##-###-### or ##-###-####).
|
||||
* @package forms
|
||||
* @subpackage fields-formattedinput
|
||||
* @see http://www.ird.govt.nz/payroll-employers/software-developers/software-specs/
|
||||
*/
|
||||
class GSTNumberField extends TextField {
|
||||
|
||||
function jsValidation() {
|
||||
$formID = $this->form->FormName();
|
||||
$error = _t('GSTNumberField.VALIDATIONJS', 'Please enter a valid GST Number');
|
||||
$jsFunc =<<<JS
|
||||
Behaviour.register({
|
||||
"#$formID": {
|
||||
validateGSTNumber: function(fieldName) {
|
||||
var el = _CURRENT_FORM.elements[fieldName];
|
||||
if(!el || !el.value) return true;
|
||||
|
||||
var value = \$F(el);
|
||||
if(value.length > 0 && !value.match(/^[0-9]{2}[\-]?[0-9]{3}[\-]?[0-9]{3,4}\$/)) {
|
||||
validationError(el,"$error","validation",false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
JS;
|
||||
Requirements::customScript($jsFunc, 'func_validateGSTNumber');
|
||||
|
||||
return "\$('$formID').validateGSTNumber('$this->name');";
|
||||
}
|
||||
|
||||
function validate($validator){
|
||||
$valid = preg_match(
|
||||
'/^[0-9]{2}[\-]?[0-9]{3}[\-]?[0-9]{3,4}$/',
|
||||
$this->value
|
||||
);
|
||||
|
||||
if(!$valid){
|
||||
$validator->validationError(
|
||||
$this->name,
|
||||
_t('GSTNumberField.VALIDATION', "Please enter a valid GST Number"),
|
||||
"validation",
|
||||
false
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user