-
15 Oct 2012 7:32 AM #1
Unanswered: Dynamic fields and validation in model
Unanswered: Dynamic fields and validation in model
Hello,
I would like to build a model from data coming from server. Is it possible to do it?
My objective is to add new fields and validations to an existing model.
Examples: current model:
For the moment, I managed to retrieve the model using the model manager (Ext.ModelManager.getModel('MyApp.model.userModel')Code:Ext.define('MyApp.model.userModel', { extend: 'Ext.data.Model', xtype: 'userModel', config: { fields: [ { name: 'name', type: 'string' }, { name: 'age', type: 'int'}, ], validations: [ {type: 'presence', field: 'name'}, {type: 'presence', field: 'age'}, ] } });
, but I can't access its properties (fields and validations items).
How could I do that?
Thank you for your answers
-
15 Oct 2012 11:03 PM #2
I tried various methods without success :
* There is no activate events where I can define it dynamically
* I tried to build a model dynamically and attached it to the store
Is it possible to do it? What am I missing?
Thank you for your support
-
16 Oct 2012 2:18 AM #3
Small update : I found this method to work :
Hope it can help someoneCode:// get Model var myModel = Ext.ModelManager.getModel('PhoneGap.model.patientModel'); // Retrieve newFields dynamically var newFields = []; newFields = eval(store.getCustomFields()); // Add each of the new field in the model for (var i = newFields.length - 1; i >= 0; i--){ myModel.prototype.fields.add(new Ext.data.Field(newFields[i])); };


Reply With Quote