AnsweredAssumed Answered

How to use indexOf() function in javascript

Question asked by Roland Cadavos on Feb 29, 2016
Latest reply on Mar 1, 2016 by Roland Cadavos

HI All,

 

I got a code and its not really working well in how I use indexOf(). Please enlighten me. Here's my code:

({
    extendsFrom:'RecordView',


    initialize:function(options){
        this._super('initialize',[options]);
        this.context.on('button:save_button:click',this.concatField, this);
    },
    concatField: function(field) {  
        var field_two_c = this.model.get('field_two_c'),
    space = " ",
    field_one_c = this.model.get('field_one_c');
    if (_.indexOf(field_one_c,field_two_c) == -1){
    this.model.set('field_one_c', field_one_c+space+field_two_c);  
   }
   else{
   this.model.set('field_one_c', field_one_c);
   }
  },
})

Everytime i click Save, the fields concats. I dont want to concat it when field_one_c contain some string from field_two_c.

 

Thanks,

Longki

Outcomes