sim4life
31 Jan 2011, 10:45 AM
Hi I'm looking for a similar solution as described in the following thread for ExtJS
http://www.sencha.com/forum/showthread.php?118555-Solved-Conditional-field-validation&highlight=validation
Basically, I have 2 fields, a selectfield and a datefield. Both are optional but if the user picks some value for selectfield then he must also pick a date in the datefield.
My partially written code is
Ext.regModel('Todo', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'},
{name: 'due_at', type: 'date'},
{name: 'remind_before', type: 'string'},
{name: 'completed_at', type: 'string'},
{name: 'todo_id', type: 'int'},
{name: 'cl_state', type: 'string'},
{name: 'action', type: 'string'}
],
validations: [
{type: 'presence', name: 'title', message: "Title is required"},
{type: 'presenceDueDate', name: 'remind_before'}
]
});
Ext.apply(Ext.data.validations,{
presenceDueDateMessage: 'Due Date is missing',
presenceDueDate: function(config, value) {
if(value == "") {
return true;
} else {
console.dir(this);
// if()//validate presence of due date
return false;
}
}
});
I think I need to write the custom validator function like presenceDueDate. In the second last line of code // if presence of due date field is validated then I return true otherwise, u guessed it, false
Secondly, the validations option of a model takes an array with its items' options as name, type, message, list etc... Exactly where in the documentation/source code are all these options listed [In case I don't have to write a custom validator?]
Anyone with any help plz!
http://www.sencha.com/forum/showthread.php?118555-Solved-Conditional-field-validation&highlight=validation
Basically, I have 2 fields, a selectfield and a datefield. Both are optional but if the user picks some value for selectfield then he must also pick a date in the datefield.
My partially written code is
Ext.regModel('Todo', {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'},
{name: 'due_at', type: 'date'},
{name: 'remind_before', type: 'string'},
{name: 'completed_at', type: 'string'},
{name: 'todo_id', type: 'int'},
{name: 'cl_state', type: 'string'},
{name: 'action', type: 'string'}
],
validations: [
{type: 'presence', name: 'title', message: "Title is required"},
{type: 'presenceDueDate', name: 'remind_before'}
]
});
Ext.apply(Ext.data.validations,{
presenceDueDateMessage: 'Due Date is missing',
presenceDueDate: function(config, value) {
if(value == "") {
return true;
} else {
console.dir(this);
// if()//validate presence of due date
return false;
}
}
});
I think I need to write the custom validator function like presenceDueDate. In the second last line of code // if presence of due date field is validated then I return true otherwise, u guessed it, false
Secondly, the validations option of a model takes an array with its items' options as name, type, message, list etc... Exactly where in the documentation/source code are all these options listed [In case I don't have to write a custom validator?]
Anyone with any help plz!