unbind - getBindData throwing error

I have 3 forms on 3 different tabs that are binded to a datatable. It works fine except when i
unbind all 3 and move from tab to tab, the initially non visible tabs throws an error when i move to the tab.
// this is basically what i am doing

var grid = $$(search.gridId);
  grid.attachEvent("onBeforeSelect",
  function (obj) {
    $$("mainView").bind(grid);
    $$("metaView").bind(grid);
    $$("lastActionView").bind(grid);
  }
);

//for new entries unbinding the datatable
//without an unbind, non visible textfields by default takes the bind values //when they are shown.

var newEntry = function () {
  var grid = $$(search.gridId);
  grid.unbind();
  $$("mainView").unbind(grid);
  $$("metaView").unbind(grid);
  $$("lastActionView").unbind(grid);
  helper.enableAllControls(false); //disable edit/delete/approve/reject controls
  editor.enableFields();
  editor.newFields();
  meta.newFields();
  lastAction.newFields();
  enableSaveButton(true);
};

the source of the error is on line 3817 of webix_debug.js - function getBindData
this._bind_update(target, this._bind_hash[key][0], this._bind_hash[key][1]);

It appears even if the targets are unbinded, the tab visibility toggle still tries to update the bind values

sometimes this._bind_hash[key] is null or sometimes this._bind_hash[key] length is zero. hence it throws an error.

The below modification with a null check and length check between
//modstart and
//modend solves the issue

	getBindData:function(key, update){
		//fire only if we have data updates from the last time
		if (this._bind_updated[key]) return false;
 //MODSTART
                if (!this._bind_hash[key] || this._bind_hash[key].length==0) return false;
//MODEND
		var target = webix.$$(key);
		//fill target only when it visible
		if (target.isVisible(target._settings.id)){
			this._bind_updated[key] = true;
			if (webix.debug_bind)
				webix.log("[bind:request] "+this.name+"@"+this._settings.id+" => "+target.name+"@"+target._settings.id);
                        this._bind_update(target, this._bind_hash[key][0], this._bind_hash[key][1]); //trigger component specific updating logic
			if (update && target.filter)
				target.refresh();
		}
	},

take a look at Code Snippet

Appreciate some feed back.

Hello,

Could you please provide more details on why do you need to unbind the forms? It seems to me that you just need to remove cursor from the master datatable to clear the bound data in all the forms: https://webix.com/snippet/45de850a

By the way, binding can be applied once, after app initialization. You don’t have to bind the forms each time before a record is selected in a datatable.

I am setting new values to the form Fields. Fields are in 3 different tabs. (This is to create new records). However even though i set new values, only the visible tab retains the new values. By default webix input fields ignores the set values and take values from the bind cursor when visibility toggles on. Hence i unbind the form before i set new values. But the unbind does not appear to occur cleanly. For some reason it still tries one more time to take values from the cursor and throws an error when the array is null.

I bind the the form later again.

I didnt try setcursor(null) before. Will do that and get back. Thanx a lot

Hi Helga,

I have tried setCursor(null) as you have suggested. But the problem of taking values from the datasource when the form becomes visible again persists.

`
var newEntry = function () {
var grid = $$(search.gridId);
grid.setCursor(null);
helper.enableAllControls(false); //disable edit/delete/approve/reject controls

    editor.enableFields();
    editor.newFields();

    rightsEditor.newFields(); //new fields populates some default values into some fields


    meta.newFields(); //new fields populates some default values into some fields
    lastAction.newFields(); //new fields populates some default values into some fields

    enableSaveButton(true);
    saveMode = 'add';

};

`

new entry populates some default values to 3 tabs. But when the form becomes visible, the form takes values from the datasource. When the cursor is null, the form populates empty values to the form fields, hence my set values are lost.

More over, the hidden forms in hidden tabs arent populated with selected row values until the tabs are visible. This causes mismatched data in the form and selected row in the datasource. If i call form.getValues() while the tab is hidden, it doesnt reflect the currently selected row in the datasource.

There are a couple of ways that works for me

1-unbinding the datasource and binding later. (This method throws error from the webix framework itself as i have mentioned above. I did a small fix as mentioned in my initial post and it works fine)

2- not binding at all, and add a row onBeforeSelect listener and parse the data into the form

Thanx

Hello,

Still, I could not reproduce the issue with unbinding. I can suggest a clean way of handling forms without having to unbind and bind them again.

If it suits you, you can initialize the multi-tab form (instead of three different ones) and handle it via setting null cursor and settings new values for all the tabs at once.

As far as I can see, such solution doesn’t have issues with datasource records and saves all the data correctly: https://webix.com/snippet/f080ac64

I havent tried your method yet. Will do and get back. But meanwhile take a look at the below snippet. This pretty much reproduces my problem

https://webix.com/snippet/2f817bcb

This is how the problem occurs.

pls Follow the sequence

  1. do not select any rows from the datatable
  2. click on new
  3. navigate to metaview
  4. select any one of the rows in the data table
  5. press save

and see the result.
Since after selecting the row, no modifications to the values were made, the save results should not be the initial new values.