1
0
Fork 0
forked from 0x2620/oxjs

change autovalidate function for input elements so that it returns, along with the new value, a valid flag that indicates if the value is already valid

This commit is contained in:
rlx 2011-10-22 14:50:31 +00:00
commit cfc5baef61
4 changed files with 23 additions and 14 deletions

View file

@ -450,10 +450,13 @@ Ox.Input = function(options, self) {
}
function autovalidateFunction(value) {
var regexp = new RegExp(self.options.autovalidate);
return value.split('').map(function(v) {
return regexp.test(v) ? v : null;
value = value.split('').map(function(v) {
return self.options.autovalidate.test(v) ? v : null;
}).join('');
return {
valid: !!value.length,
value: value
};
}
function autovalidateTypeFunction(type, value) {
@ -467,7 +470,6 @@ Ox.Input = function(options, self) {
+ '$)'
) : new RegExp('(^' + (self.options.min < 0 ? '\\-?' : '') + '\\d+)');
if (type == 'float') {
//Ox.print('--float--', value)
if (value === '') {
value = '0.' + self.decimals;
cursor = [0, value.length];
@ -484,7 +486,6 @@ Ox.Input = function(options, self) {
value = '0' + value;
cursor = [2, value.length];
} else if (/\.$/.test(value)) {
//Ox.print('$$$$$$$$$$$')
value += self.decimals;
cursor = [value.indexOf('.') + 1, value.length];
} else if (/\./.test(value) && self.options.decimals) {
@ -510,18 +511,23 @@ Ox.Input = function(options, self) {
value = oldValue;
cursor = oldCursor;
}
autovalidateCallback(value, cursor);
autovalidateCallback({
cursor: cursor,
valid: true,
value: value
});
}
function autovalidateCallback(newValue, newCursor) {
function autovalidateCallback(data) {
//Ox.print('autovalidateCallback', newValue, oldCursor)
self.options.value = newValue;
self.options.value = data.value;
self.$input.val(self.options.value);
!blur && cursor(
newCursor || (oldCursor[1] + newValue.length - oldValue.length)
data.cursor || (oldCursor[1] + data.value.length - oldValue.length)
);
that.triggerEvent('autovalidate', {
value: self.options.value
valid: data.valid,
value: data.value
});
}