question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: callback for field/model initialisation

See original GitHub issue
[x] feature request

It would be nice to have an initialisation callback before fields are populated. For example:

  • In the Repeating Type, when model data exists, the FieldGroups are already populated, before the FieldArrayType implementation’s ngOnit runs. Having a callback would simplify the code. https://stackblitz.com/edit/angular-abr1eg?file=src/app/datatable.type.ts

  • In the Repeating Type to populate buttons.

  • In the Repeating Type to populate a first row in the model when no model data exists.

Some of this can be done before it is handed over to formly, but I think it also makes sense to have the option to have it as near to the library as possible.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
aitboudadcommented, Aug 28, 2018

good news, I figure-out that there is a way to create the field component instance too early so there a hope to have a such feature out of the box!

1reaction
FritzHerberscommented, Aug 13, 2018

@aitboudad Great, your extension works as expected. It can solve to reduce complexities in the custom type’s code. Thanks a lot.

To use a field config implementation is not my favored one. To use a custom type the app component (by field config) has to provide code which needs to interact with the behaviour of the custom type or even provide the full code for the custom type’s intend.

To overcome this, before handing over the field config to formly an application can call a service which traverses through the field config, modifies the field config for a custom type and also provides the populate code.

The idea of a custom type is to have an interface (by an as simple as possible field config) and a behaviour/semantics. It interacts closely with the formly library and shields of the implementation for it’s users (app component) (and even more the implementation of the formly library).

I was hoping more for a coded solution, extending a populate method in the derived custom type: TypeScript extending example

Are there any drawbacks or implications using such a solution?

The field config implementation can be valuable for specific situations. Would be great to have an additional “coded” solution.

For the time being I will go the above described “using a service” path.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initialization Function - MATLAB & Simulink - MathWorks
Use the model InitFcn callback to initialize parameters and environment settings that are specific to the model, for example: Variables used in model...
Read more >
best way to handle callback initialization and functions that ...
I think it woull be better to have the callback function initialized, so that the arrays are created, and then call the functions...
Read more >
Initializing callbacks - IBM
All callbacks must be identified when you call the IMCreate subroutine. The IMCallback structure contains the address for each callback function.
Read more >
CS 211 Lesson 30 GUI Components
Lesson Objectives: Be able to share values between callback functions. Be able to initialize GUI state. Be able to get and set GUI...
Read more >
Documentation: 15: 51.1. Initialization Functions - PostgreSQL
To provide the required archive module callbacks and to indicate that the ... needs to be filled with the callback function pointers for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found