AnsweredAssumed Answered

Change field value in create.js

Question asked by Rodrigo Morchio on Feb 3, 2017
Latest reply on Apr 20, 2017 by delsugar

Hi,

 

I need to parse a field value in record and create view to only leave the numeric characters dynamically. I've modified both record and create.js capturing the change event on that field and then setting the value with this.model.set('field','value'). It works perfectly in record.js (the field value is changed as soon as I focus out of the field - expected result) but in create.js the changes are not reflected until the record is saved.

 

Here's my record.js:

({

extendsFrom: 'RecordView',

initialize: function(options) {
    this._super('initialize', [options]);
    this.model.on("sync",function(){this.model.on("change:cuit_rut_ruc_c",this._parsearClaveTributaria,this);},this);   
},

_parsearClaveTributaria: function () {
   
    this.model.set('cuit_rut_ruc_c',this.model.get('cuit_rut_ruc_c').replace(/\D/g,''));
},

_dispose: function() {
     this._super('_dispose');
},

})

 

And this is my create.js:

 

({

extendsFrom: 'CreateView',

initialize: function(options) {
    this._super('initialize', [options]);
    /* I understand the 'sync' event is not needed as I'm creating the record */
    this.model.on("change:cuit_rut_ruc_c",this._parsearClaveTributaria,this);
},

_parsearClaveTributaria: function () {
    /* This line replaces the field value leaving only digits */
    this.model.set('cuit_rut_ruc_c',this.model.get('cuit_rut_ruc_c').replace(/\D/g,''));
    /* I added the following lines trying to make it work,
       I also tested it without these lines */

    var claveTributaria = this.getField('cuit_rut_ruc_c');
    claveTributaria.render();                              
},

_dispose: function() {
     this._super('_dispose');
},

})

 

I'd appreciate any help on this. I'm using SugarCRM 7.7.2.0.

 

Kind Regards,

Rodrigo

Outcomes