AnsweredAssumed Answered

Field validation on pop-up create (create.js not working)

Question asked by Arpad Szabo on Aug 16, 2017

Good day Developers!

 

In our Sugar instance (Sugar CRM Enterprise 7.9.1.0 (Build 1074)) previously since 7.8 version created custom validations on our modules. 

 

We used first the create-actions.js, then the create.js and record.js method for this purpose.Then added some custom error messages as well according to the Sugar developer documentation:

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/User_Interface/Views/Adding_Field_V… 

 

And worked fine. 

 

The problem:

When from an existing record creating a new record (in the related, Validated module) with pop-up create method, the validation in the create.js doesn't triggers. 

 

Back in the 7.8 versions when we developed these validations seemed to work at pop-up create, but I'm not sure.

 

Is anybody familiar with this issue?

The linked developer guide only shows the create.js and record.js files to need to be created... 

Is there different ".js" in the views needed to be created?

 

Thank You for Your help, 

Regards,

Arpad

 

Our create.js code is the following:

//Place here: custom/module/MOBIL_AutoFoglalasok/clients/base/views/create/create.js
//Validate on creating new record
({
     
     extendsFrom: 'CreateView',
     initialize: function(options){
          this._super('initialize', [options]);
          
          //Error messages
          app.error.errorName2Keys['hasznalat_start_error']     ='ERR_GEFO_HASZNALAT_START';
          app.error.errorName2Keys['hasznalat_end_error']          ='ERR_GEFO_HASZNALAT_END';
          app.error.errorName2Keys['kiadas_error']               ='ERR_GEFO_KIADAS';
          app.error.errorName2Keys['visszavetel_error']          ='ERR_GEFO_VISSAVETEL';
          

          //Validations
          this.model.addValidationTask('check_hasznalat_start', _.bind(this._doValidateHasznalatStart, this));
          this.model.addValidationTask('check_hasznalat_end', _.bind(this._doValidateHasznalatEnd, this));
          this.model.addValidationTask('check_kiadas', _.bind(this._doValidateKiadas, this));
          this.model.addValidationTask('check_visszavetel', _.bind(this._doValidateVisszavetel, this));
               
          },

     _doValidateHasznalatStart:function (fields, errors, callback){
          var plannedUsageStart = new Date(this.model.get('gefo_hasznalat_terv_kezdet_c'));
          var reservationDate = new Date (this.model.get('gefo_foglalas_leadasa_c'));
               
          
          if(reservationDate > plannedUsageStart) {
               errors['gefo_hasznalat_terv_kezdet_c'] = errors['gefo_hasznalat_terv_kezdet_c'] || {};
               errors['gefo_hasznalat_terv_kezdet_c'].hasznalat_start_error = true;
          }
     callback(null, fields, errors);     
     },
     
     _doValidateHasznalatEnd:function (fields, errors, callback){
          var plannedUsageStart = new Date(this.model.get('gefo_hasznalat_terv_kezdet_c'));
          var plannedUsageEnd = new Date(this.model.get('gefo_hasznalat_terv_vege_c'));
                    
          
          if(plannedUsageStart > plannedUsageEnd) {
               errors['gefo_hasznalat_terv_vege_c'] = errors['gefo_hasznalat_terv_vege_c'] || {};
               errors['gefo_hasznalat_terv_vege_c'].hasznalat_end_error = true;
          }
     callback(null, fields, errors);     
     },
     
     _doValidateKiadas:function (fields, errors, callback){
          var plannedUsageStart = new Date(this.model.get('gefo_hasznalat_terv_kezdet_c'));
          var releasingDate = new Date(this.model.get('gefo_kiadas_ideje_c'));
          
          
          if(plannedUsageStart > releasingDate){
               errors['gefo_kiadas_ideje_c'] = errors['gefo_kiadas_ideje_c'] || {};
               errors['gefo_kiadas_ideje_c'].kiadas_error = true;
          }
     callback(null, fields, errors);
     },
     
     _doValidateVisszavetel:function (fields, errors, callback){
          var plannedUsageStart = new Date(this.model.get('gefo_hasznalat_terv_kezdet_c'));
          var recaptureDate = new Date(this.model.get('gefo_visszavetel_idopontja_c'));
          
          if(plannedUsageStart > recaptureDate){
               errors['gefo_visszavetel_idopontja_c'] = errors['gefo_visszavetel_idopontja_c'] || {};
               errors['gefo_visszavetel_idopontja_c'].visszavetel_error = true;
          }
     callback(null, fields, errors);     
     }
})

Outcomes