1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    18
    Vote Rating
    1
    Answers
    2
    neoraptor is on a distinguished road

      0  

    Default 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:
    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'},
    		]
        }
    });
    For the moment, I managed to retrieve the model using the model manager (Ext.ModelManager.getModel('MyApp.model.userModel'), but I can't access its properties (fields and validations items).
    How could I do that?

    Thank you for your answers

  2. #2
    Sencha User
    Join Date
    Jun 2012
    Posts
    18
    Vote Rating
    1
    Answers
    2
    neoraptor is on a distinguished road

      0  

    Default


    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

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    18
    Vote Rating
    1
    Answers
    2
    neoraptor is on a distinguished road

      1  

    Default


    Small update : I found this method to work :

    Code:
    // 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]));
    };
    Hope it can help someone