PDA

View Full Version : Is a model required for an errorReader?



bmacdon1
16 Aug 2011, 12:54 PM
Hello,
I have been struggling attempting to get the errorReader(or even xml data) to work properly on a form submit without using a model. The code snippet below comes from the api section Ext.form.action.Submit (http://docs.sencha.com/ext-js/4-0/#/api/Ext.form.action.Submit) and implies to me it is not necessary to build a model for a simple reader.




errorReader: new Ext.data.reader.Xml({
record : 'field',
success: '@success'
}, [ 'id', 'msg' ])



I ended up using the Extjs XML sample (http://dev.sencha.com/deploy/ext-4.0.2a/examples/form/xml-form.html) to get the submit somewhat working. This sample required the use of a model. On a side note, this functionality doesn't work for me on the sample page. The submit is always disabled.

If I don't include a model I get an error "this.model is undefined." The closest post I've found dealing with a similar issue is here:

(http://www.sencha.com/forum/showthread.php?133382-Problems-using-action.Load-with-XML-Reader-%28migrating-from-3.x-to-4.x%29)Problems using action.Load with XML Reader (migrating from 3.x to 4.x) (http://www.sencha.com/forum/showthread.php?133382-Problems-using-action.Load-with-XML-Reader-%28migrating-from-3.x-to-4.x%29)

No one answered his question, but it seems similar to what I am dealing with. This is a snippet of my code. It is possible I am doing something wrong all together and it would be great if someone could point me in the right direction. And yes, I know its over kill to be doing this for a log in page, but I am attempting to rely on ExtJS framework to build everything.



var loginForm = Ext.create('Ext.form.Panel',
{
title: 'Login Form',
bodyPadding: 5,
width: '462',
height: '333',
autoScroll:true,
url: '../login',
clientValidation:false,
errorReader: Ext.create('Ext.data.reader.Xml', {
record : 'MESSAGE',
success: '@success'
},['MESSAGE_TYPE'])
});

var loginFormButtonsubmit= Ext.create('Ext.Button',{
text: 'Submit',
formBind: true,
handler: function()
{
var form = this.up('form').getForm();

if (form.isValid())
{

form.submit({
success: function(form, action){
alert('Success')
},
failure: function(form, action){
alert('Failed')
}
});
}
else
{
Ext.Msg.alert('', 'This page contains errors. Correct the errors indicated below each field, and then retry this action.')
}
}
});

loginForm.add(loginFormButtonsubmit);

bmacdon1
17 Aug 2011, 4:11 AM
Nice, to see the example is fixed now ;p

robertb216
18 Feb 2012, 6:58 PM
I have attempted the exact same thing for my login page. I'm use Ext 4.1 and get the error "this.model.prototype.fields.items;" undefined...

On my form config..
<code>
errorReader: new Ext.data.reader.Xml({
record : 'field',
success: '@success'
}, [ 'id', 'msg' ]
),
</code>

and in my controller with the "login button"
<code>
onLoginClick: function() {
....
myForm.submit({
method: 'POST',
waitTitle: 'Connecting',
waitMsg: 'Sending data...',


success:function(form,action){
...do something like load new url...
},
failure:function(form, action){
... let user know that email/password was invalid...
}
});
</code>

this looks to be the same problem you were having.... any suggestions ??

glandi
4 Jul 2012, 3:53 AM
If you don't have to rebind the xml response to the form,
you can make an ajax request with form values as params and extract the desired node from the response with Ext.DomQuery.


var request = {
url: myUrl, params: myForm.getValues(), method:'post',
callback: this.requestCallback, scope:this,
};
Ext.Ajax.request(request);

requestCallback:function(options, success, response) {
var msg = null;
if (success) {
try {
var xml = response.responseXML;
success = Ext.DomQuery.selectValue('success', xml) == "true";
if (!success) {
msg = "Request failed";
}
} catch(e) {
msg = "Cannot decode XML response "+e +" "+ response.responseText;
}
} else {
msg = response.responseText;
}
if (!success) {
Ext.Msg.alert("Failure", msg);
}
}

koushlendr
3 Oct 2013, 4:27 AM
1. json response after form submit ::

{"success":"false","errors":[{"id":"java.home","msg":"Java Home is required and cannot be empty"},{"id":"admin.password","msg":"AppServer Admin Password is required and cannot be empty"}]}

2. ErrorReader configuration in form ::

errorReader : new Ext.data.reader.Json({
root: 'errors',
successProperty: 'success',
model : 'Manh.model.layout.install.InstallErrors'
}),

3. Model definition for error reader:

Ext.define('Manh.model.layout.install.InstallErrors', {
extend: 'Ext.data.Model',
fields: ['id', 'msg']
});

Still error reader not working as i get model undefined in ext-all-dev.js on below lines.

if (me.lastFieldGeneration !== me.model.prototype.fields.generation) {
me.buildExtractors(true);
}

Need help to resolve this.