AnsweredAssumed Answered

Sugar 7 - CreateView field logic breaking form

Question asked by Ramon Marcondes on Jul 1, 2016
Latest reply on Jul 4, 2016 by Ramon Marcondes

Hello.

I use Sugar Enterprise 7.7.

Only recently I got form validation on page load to work.

But there is a problem: the validation I done actually changes the field value by changing it's model value, but it's giving a javascript error, blocking the form from submitting.

 

This is the code:

({      
    extendsFrom: 'CreateView',      
    initialize: function(options) {                           
        this._super('initialize', [options]);                                        
        this.on('render', _.bind(this.testFunc, this));  
    },      
    testFunc: function() {        
        console.log("Test");      
        _.each(this.fields, function(field) {      
            if (_.isEqual(field.def.name, 'data_init')) {      
                console.log(field);  
                 
                var datetime = new Date();       
                console.log("Datetime: "+datetime);  
                 
                model.set({data_init: datetime});  
                console.log("Value: "+field.value);    
            }      
        }, this);     
    },      
})  

 

And this is the error:

Uncaught TypeError: val.match is not a function at https://sandboxitapoa.sugarondemand.com/sidecar/minified/sidecar.min.js?v=6LrdnWcZoAMs1F3Gh1Cz1g on line 17write @ logger.js:123

date.js:867Uncaught TypeError: val.match is not a function

 

What I'm missing? What I should do to set the model value correctly?

Maybe it sounds like something basic, but my knowledge on backbone.js and underscore.js is still limited. I'm still searching an learning some things.

Any help would be appreciated.

 

Thanks!

Outcomes