Skip to Content
Menu
This question has been flagged
1 Reply
11541 Views

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.

Avatar
Discard
Best Answer

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!

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 24
4479
2
Dec 22
2469
1
Nov 19
18387
1
Feb 18
6289
1
Aug 16
4925