Setting complex data in a form

GeeGee
edited February 2018 in Technical questions

On selecting an item in the dataview I obtain the data with the following call

var item = webix.$$("Data").getItem(id); 

and store this in status.js state.data

I then change view as follows this.$scope.show("data_edit");

In this view I have set the data for the view to state.data

data : state.data

This works just fine for the first item I enter the form.

When I exit the form and go back to the dataview and select another item to edit I end up with the previous data in the form

I have addressed this using onAfterLoad

onAfterLoad: function () {

    webix.message('onAfterLoad editDetails');

    this.setValues({ field1: state.data.field1 });

    this.refresh();

},

I tried and I had through I could do the following

onAfterLoad: function () {

    webix.message('onAfterLoad editDetails');

    this.setValues({ data: state.data });

    this.refresh();

},

That way I would not have to set each individual field, but this just didn't work.

I also set complexData: true properity in the form, no luck at all.

As I'm setting data in onAfterLoad I thought I might not need set data in the form but I do.

My question is, is this the correct way to do this. I would prefer to just set data to state.data as follows, its clean and when I save the data I will have the whole item.

onAfterLoad: function () {

    this.setValues({ data: state.data });

    this.refresh();

},

Any suggestions would be much appreciated.

Tagged:

Comments

  • It seems that the same works for me

    https://snippet.webix.com/29xi24if

    The approach with storing data in the external object is not the best one though, it will be better to have a separate model and transfer just a reference to the selected data record.

        return { view:"list", click:function(id){
          this.$scope.show("form?id="+id);
        }}; 
    
      init(view){
        const obj = model.getItem(this.getParam("id"));
        view.setValues(obj);
      }
    

    https://snippet.webix.com/xdrtfzsf

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion