allow validate to change submitted value, fixes

This commit is contained in:
vitalets
2013-10-10 20:36:36 +04:00
parent 8efa4060c5
commit df3e2daffd
3 changed files with 86 additions and 5 deletions
CHANGELOG.txt
src/editable-form
test/unit

@ -199,9 +199,18 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
//get new value from input
var newValue = this.input.input2value();
// validation: if validate returns truthy value - means error
// validation: if validate returns string or truthy value - means error
// if returns object like {newValue: '...'} => submitted value is reassigned to it
var error = this.validate(newValue);
if (error) {
if ($.type(error) === 'object' && error.newValue !== undefined) {
newValue = error.newValue;
this.input.value2input(newValue);
if(typeof error.msg === 'string') {
this.error(error.msg);
this.showForm();
return;
}
} else if (error) {
this.error(error);
this.showForm();
return;
@ -500,6 +509,8 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
send: 'auto',
/**
Function for client-side validation. If returns string - means validation not passed and string showed as error.
Since 1.5.1 you can modify submitted value by returning object from `validate`:
`{newValue: '...'}` or `{newValue: '...', msg: '...'}`
@property validate
@type function