AnsweredAssumed Answered

Custom Field Type field definition mandatory_fetch not working

Question asked by Artis Plocins on Sep 13, 2018
Latest reply on Sep 14, 2018 by Artis Plocins

I have built a Custom Field Type similar to the built-in Relate field which stores a record name and requires two additional custom fields alongside it to store the record ID and module. I have not inherited from the relate field because the functionality doesn't suit my use case.

 

I have the main field, let's say custom_relate_c which is added to a layout. When it is saved, it also saves values in additional fields created by the Dynamic Field template class TemplateCustomRelate.php called custom_relate_id_c and custom_relate_module_c.

Then, when I reload the view, I can see that only the main field custom_relate_c has been fetched and the other two are not on the model. To get these fields, I have to fetch both of them specifically using fetch again:

model.fetch({fields: [...]})

 

I have tried adding the mandatory_fetch field definition to the additional ID and module fields, but that never appears in the field definitions when checking on the front end.

 

I have also tried adding the field definition group on all three fields so that their group is the same: custom_relate_c.

 

Fetching after the model has been synced in the JS controller is bad because it introduces another delay for displaying the field after the whole view has been rendered fully (apart from my custom field because of this issue).

 

And, of course, it would also be a bad idea to store all three values concatenated within the main custom_relate_c field itself, because that would not make sense in reports and any other basic functionality.

 

Note that I save a reference to the names of the additional fields in one field definition related_fields in JSON format, which I parse in the JS controller to get their values from the model.

 

Could you please share any experience you might have with creating custom field types and ensuring that some fields which are not on the layout are configured to always be fetched?

Outcomes