PDA

View Full Version : Custom Ext.data.Types and binding to form



Avman2119
3 Oct 2012, 2:31 PM
So I have a custom type


Ext.data.Types.REVIEWCOMMENT = {
convert: function(v, data) {
return Ext.ModelMgr.getModel('reviewerCommentModel').create({
CommentId: v.CommentId,
ReviewId: v.ReviewId,
UPN: v.UPN,
ReviewerName: v.ReviewerName,
ReviewerType: v.ReviewerType,
ResponseDate: v.ResponseDate,
NoComment: v.NoComment,
FileManagerId: v.FileManagerId,
FileName: v.FileName,
Comment: v.Comment
});
},
type: 'ReviewComment'
}

then my model has a field of


{ name: 'MyComment', type: 'ReviewComment' }

In my form after loading the record to the form using

{ xtype: 'htmleditor',
name: 'MyComment.data.Comment',
width: '100%',
height: 200,
enableFont: false,
enableSourceEdit: false,
margin: '10 0 10 0'
},

The data in the field doesn't show up? What am I doing wrong?

skirtle
4 Oct 2012, 1:58 AM
name: 'MyComment.data.Comment',

If you're using loadRecord to pull your data into the form then using a name like this won't drill down into your field in the way you're expecting.

If you want to use loadRecord you'll have to pull the Comment out to its own field on your main record.

Avman2119
4 Oct 2012, 6:21 AM
So what you're saying is there is no way to use the custom "complex" datatype within another model to bind to a form?

skirtle
4 Oct 2012, 6:39 AM
So what you're saying is there is no way to use the custom "complex" datatype within another model to bind to a form?

It is possible but it'll require you to implement some of the logic yourself. You could override setValues on the form or maybe the setValue method of the field.

Take a look at the source to loadRecord and follow it through to see how it works behind the scenes. It isn't very complicated, it just copies the record's values across to fields with the same names:

http://docs.sencha.com/ext-js/4-1/source/Basic.html#Ext-form-Basic-method-loadRecord

Avman2119
4 Oct 2012, 6:43 AM
How would I override a setValues method for either the form or the field?