跳至內容
選單
此問題已被標幟
1 回覆
11562 瀏覽次數

I'm migrating a custom widget from v10 to v11 and despite I did manage to make it work, I don't feel like I used framework as it was supposed to be used. I have 2 questions:

1. How should I retrive up to date value of an model record?

Before v11 I used to do that like this:

this.field_manager.get_field_value("field_name")

Now when I have record it only gives me last saved state. As workaround I subscribed to renderers "field_changed" event and I have to internally track current value of fields I need.

1a. Is there a way to somehow subscribe only to single field change event?


In 10.0 I used to check if field is in readonly mode like this:

this.field_manager.fields["field_name"].get("effective_readonly")

In 11.0 the only way I managed to get readonly status was like this:

this.renderer.allFieldWidgets[this.record.id]
    .find(widget => widget.name === "field_name").mode === "readonly";


This seems so bad to me.

2. What would be the proper way ?

I searched through docs that @ged is working on, but there is nothing about this, and i wasn't able to figure out how this should be done.

頭像
捨棄
最佳答案

Your feedback is appreciated. I know that the documentation is really not up to the task, but it is just a start. Meanwhile, let me try to answer your questions:

  1. You can access all field values by using the recordData object: this.recordData[some_other_field]. If you need up to date data, then you should set the resetOnAnyFieldChange attribute to true. By default, field widgets are only notified when their value change. You need to explicitely ask for update (this is for performance reasons).

1a: a big difference in 11.0 is that fields are not notified when their mode (edit/readonly) changes. When this happens, they are destroyed and recreated

If this is not clear, please tell me!

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
3月 24
4547
2
12月 22
2504
1
11月 19
18413
1
2月 18
6321
1
8月 16
4950