allow validate
to change submitted value, fixes #400
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user