How do you add js to a record edit view in Sugar7?

before, I will wrote some js files and include them in editviewdef.php,and everything was fine,like 'displayParams' , $.ajax to get values .However ,when I fall in Sugar7,it seems that even I want to alert('hello') is a problem.

Now, I hope someone kind could give an method to include js file . specifically,in account ,I can use formula to make field A = filed B+ field C, but the field A can not be edit for using formula.I would use js to calculate it in th pass ,and certainly it could be edit .Now, how should I do?

Thanks


Parents
  • If you customize the record view (clients/base/views/record) HandleBars for example and include a JavaScript tag there for example. A better solution is to extend the controller and try to add all module specific clientside functionality there.

    But for the issue you try to solve: you want that the value of field A is equal to B+C. This can be done by creating a formula for Field A, but you do not want to do this because it makes the field not editable anymore (so Field A is some sort of default value?) ? In that case then maybe a Logic Hook might be a better solution, for example a before_Save logic hook which sets the appropriate value for Field A before it is saved.
  • make a record.js file in
    and put this code

    ({
        extendsFrom: 'RecordView',
        initialize: function (options) {
            app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});
            alert ("done");
            alert (this.model.get('id'));// this will show the current record id i wrote this line to make u understand how to get any field value
           
        }

    })

  • Write the following code in record.js file

    ({
            extendsFrom: 'RecordView',     
            initialize: function (options) {
            app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});
         
            //Onchange of B and C fields call validation method
            this.model.on("change:FieldB",this.validation, this);
            this.model.on("change:FieldC",this.validation, this); 

    },

    validation:function() {
           //Write your logic here
    },

    })


Reply
  • Write the following code in record.js file

    ({
            extendsFrom: 'RecordView',     
            initialize: function (options) {
            app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});
         
            //Onchange of B and C fields call validation method
            this.model.on("change:FieldB",this.validation, this);
            this.model.on("change:FieldC",this.validation, this); 

    },

    validation:function() {
           //Write your logic here
    },

    })


Children