Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    getSelectedRecord() ComboBoxItem null

    1. v100p_2014-11-20_LGPL

    When you're using a ComboBoxItem with an optionDataSource to fetch missing displayvalue's, getSelectedRecord will be null after the first redraw. This is because the displayFieldCache is not checked to resolve the selectedRecord, but it is used to display the displayvalue.

    A workaround is to overwrite getSelectedRecord in ComboBoxItem:
    Code:
    	getSelectedRecord: function(){
    		var selectedRecord = this.Super('getSelectedRecord',arguments);
    		if(selectedRecord == null && this._displayFieldCache!=null){
    			selectedRecord = this._displayFieldCache.find(this.getValueFieldName(),this.getValue());
    		}
    		return selectedRecord;
    	},

    #2
    Hi dencel,
    Thanks for the suggestion. Can you clarify what you mean when you say getSelectedRecord will be null after the first redraw?
    A way to reproduce the problem this proposed patch addresses would be helpful (either steps to reproduce in one of our shipped samples, or a test case we can copy/paste into our environment and see the problem in action).

    Regards
    Isomorphic Software

    Comment


      #3
      Please test the following example in http://www.smartclient.com/docs/10.0/a/system/reference/SmartClient_Explorer.html#jsonDataSource:
      You'll see that the selected record is null, although the selectedrecord is used in the formatValue.
      Code:
      isc.DataSource.create({
          ID:"countries",
          dataFormat:"json",
          dataURL:"[ISOMORPHIC]/system/reference/inlineExamples/grids/data/countryData.json",
          fields:[
              {name:"countryCode",primaryKey:true},
              {name:"countryName"}
          ]
      });
      isc.VLayout.create({
        members:[isc.DynamicForm.create({
         ID:"myForm",
         values: {country:"US"},
         fields:[{name:"country",formatOnBlur: true,width:250,
      	editorType:"ComboBoxItem",formatValue: function(value,record,form,item){
              if(item.getSelectedRecord()) return item.getSelectedRecord().countryName + " - "+ item.getSelectedRecord().capital + "";
              return value;
      
      }, 
       optionDataSource:"countries",valueField:"countryCode",displayField:"countryName"}]
      }),
      isc.Button.create({
        title:"Please click me to test",
        width:200,
        click: function(){
           isc.say("Selected record is : " + (myForm.getItem("country").getSelectedRecord()));
       }
      })]
      });
      Now test it with the workaround:
      Code:
      isc.ComboBoxItem.addMethods({
      	getSelectedRecord: function(){
      		var selectedRecord = this.Super('getSelectedRecord',arguments);
      		if(selectedRecord == null && this.$847!=null){
      			selectedRecord = this.$847.find(this.getValueFieldName(),this.getValue());
      		}
      		return selectedRecord;
      	}	
      });
      
      isc.DataSource.create({
          ID:"countries",
          dataFormat:"json",
          dataURL:"[ISOMORPHIC]/system/reference/inlineExamples/grids/data/countryData.json",
          fields:[
              {name:"countryCode",primaryKey:true},
              {name:"countryName"}
          ]
      });
      isc.VLayout.create({
        members:[isc.DynamicForm.create({
         ID:"myForm",
         values: {country:"US"},
         fields:[{name:"country",formatOnBlur: true,width:250,
      	editorType:"ComboBoxItem",formatValue: function(value,record,form,item){
              if(item.getSelectedRecord()) return item.getSelectedRecord().countryName + " - "+ item.getSelectedRecord().capital + "";
              return value;
      
      }, 
       optionDataSource:"countries",valueField:"countryCode",displayField:"countryName"}]
      }),
      isc.Button.create({
        title:"Please click me to test",
        width:200,
        click: function(){
           isc.say("Selected record is : " + (myForm.getItem("country").getSelectedRecord()));
       }
      })]
      });

      Comment


        #4
        We've found the cause of this and fixed it.
        Please try the next nightly build, dated March 21 or above (10.0 or 10.1 branch)

        Thanks
        Isomorphic Software

        Comment


          #5
          This works, thanks.

          Comment

          Working...
          X