I'm having some trouble getting a form to validate with Sencha Architect/Touch. I've created a model:
Code:
Ext.define('MyApp.model.MyModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{
allowNull: false,
name: 'firstName',
type: 'string'
},
{
allowNull: false,
name: 'lastName',
type: 'string'
},
{
name: 'emailAddress',
type: 'string'
},
{
name: 'businessNumber',
type: 'string'
},
{
name: 'mobileNumber',
type: 'string'
}
],
validations: [
{
type: 'email',
field: 'emailAddress'
},
{
type: 'presence',
field: 'firstName'
},
{
type: 'presence',
field: 'lastName'
},
{
type: 'length',
field: 'firstName',
min: 3
},
{
type: 'format',
field: 'firstName\''
}
]
}
});
A form panel:
Code:
Ext.define('MyApp.view.MyFormPanel', {
extend: 'Ext.form.Panel',
config: {
id: 'testform',
url: 'process.php',
items: [
{
xtype: 'fieldset',
title: 'Contact Information',
items: [
{
xtype: 'textfield',
label: 'First Name:',
name: 'firstName'
},
{
xtype: 'textfield',
label: 'Last Name:',
name: 'lastName'
},
{
xtype: 'emailfield',
label: 'Email:',
name: 'emailAddress',
placeHolder: 'email@example.com'
},
{
xtype: 'textfield',
label: 'Business Number:',
name: 'businessNumber'
},
{
xtype: 'textfield',
label: 'Mobile Number:',
name: 'mobileNumber'
},
{
xtype: 'toolbar',
docked: 'bottom',
items: [
{
xtype: 'button',
ui: 'round',
text: 'Load Model'
},
{
xtype: 'spacer'
},
{
xtype: 'button',
handler: function(button, event) {
button.up('#testform').reset();
},
text: 'Reset'
},
{
xtype: 'button',
id: 'saveBtn',
ui: 'confirm',
text: 'Save'
}
]
}
]
}
]
}
});
A controller:
Code:
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
config: {
refs: {
saveBtn: '#saveBtn'
},
control: {
"saveBtn": {
tap: 'onSaveTap'
}
}
},
onSaveTap: function(button, e, options) {
var values = button.up('#testform').getValues();
var mymodel = Ext.create('MyModel', values);
var errs = mymodel.validate();
if (!errs.isValid()) {
errs.each(function(err) {
console.log(err.getMessage());
});
}
}
});
When I attempt to validate the form, the following warning and error occurs:
[WARN][Anonymous] [Ext.Loader] Synchronously loading 'MyModel'; consider adding 'MyModel' explicitly as a require of the corresponding class
GET http://localhost/FT/MyModel.js 404 (Not Found)
Uncaught Error: [Ext.Loader] Failed loading synchronously via XHR: 'MyModel.js'; please verify that the file exists. XHR status code: 404
Not sure why it is looking for "MyModel.js" in the "root" of my application, it should be looking in app/Model/...
While I am asking ... how do I add a matcher/regexp to the "format" validation with SA?
Any suggestions please?
Thanks.