-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Form Control sample example Needs #762
Comments
@NuruddinBadawi You need to state which For example if you'd like to replace the default select component of a certain UI package you would do this:
|
Thanks to your replay @udos86, but if I need to make new type not override, for example, I have |
@NuruddinBadawi Yes, it technically should be possible to introduce a custom But please beware that there's currently no support for recreating a custom dynamic form control model from JSON. |
@udos86 As for the I'm just asking a question here. We are having a similar need at the moment, I'm evaluating our options. Thanks! |
I'm trying to build a custom component based on the autocomplete from primeng with a rest-backend to get a list of suggestions, do u have an example on how to build your own model? |
@udos86 Can you clarify the below
Where does this limitation come from? I'm happy to put in some work to enable this as this is a key requirement for us. Here is what we are trying to achieve:
At first glance introducing custom |
Did some digging:
Would be the right approach to implement DYNAMIC_FORM_CONTROL_MODEL_MAP_FN similar to the ones for form controls? |
I have a proof-of-concept working where I can create a dynamic form from JSON with a custom control. I implemented a custom In order to get loading from JSON working, I had to extend
Then I set my app to use my overriden DynamicFormService class via
This works, but it doesn't feel like the most robust way of doing this. |
The documentation states that by using this approach we can override the default mapping however, it is not clear for the first sight that this library is NOT extendable. I choose this library because I saw the custom controls section in documentation and it seemed to do exactly what I wanted. Only when got familiar with the library I had to realize that I have to implement the actual behavior myself. I find the documentation to be misleading in this regard. I read a few issues here and I saw that a lot of us would be happy to contribute in order to make this library better, but there was no answer from the maintainer side. I am a bit disappointed about this. I had to implement visibility relations myself and I am going to implement true customization as well, because we need this behavior in our project. It would also be good if I was able to use my forked source in my project, but due to the fact that the library contains multiple packages I did not find a way to include this git in packages.json. I had to copy and paste the relevant parts of source code into my project - which sounds ridiculous. So if anyone can share some solution about these problems, I would be happy to share my contribution to this library. Thx |
Now, I describe here what I basically did in order to implement this behavior, maybe it helps someone. In order to implement a real custom control behavior I declared a new function signature and an injection token for the model selector in dynamic-form.service.ts
this should be injected in constructor:
then in DynamicFormService.fromJSON the
then I use it via a provider in my module:
the custom model should define the inherited type field as serializable:
everything else is done by the docs |
Thanks it's really helpful. Do u have this in any stackblitz or any github
repo. I am new to this lib and find it difficult where all to make the
changes
…On Thu, 28 Mar, 2019, 3:54 AM danielleiszen, ***@***.***> wrote:
Now, I describe here what I basically did in order to implement this
behavior, maybe it helps someone.
In order to implement a real custom control behavior I declared a new
function signature and an injection token for the model selector in
dynamic-form.service.ts
export type DynamicFormModelMapFn = (type: string, model: any, layout: any) => DynamicFormControlModel | null;
export const DYNAMIC_FORM_MODEL_MAP_FN = new InjectionToken<DynamicFormModelMapFn>("DYNAMIC_FORM_MODEL_MAP_FN");
this should be injected in constructor:
constructor(
@Inject(DYNAMIC_FORM_MODEL_MAP_FN) @optional() private readonly DYNAMIC_FORM_MODEL_MAP_FN: any,
private validationService: DynamicFormValidationService) {
this.DYNAMIC_FORM_MODEL_MAP_FN = DYNAMIC_FORM_MODEL_MAP_FN as DynamicFormModelMapFn;
}
then in DynamicFormService.fromJSON the default case has been extended as:
default:
{
if (this.DYNAMIC_FORM_MODEL_MAP_FN !== undefined) {
var model = this.DYNAMIC_FORM_MODEL_MAP_FN(model.type, model, layout);
if (model !== null) {
formModel.push(model);
}
} else {
throw new Error(`unknown form control model type defined on JSON object with id "${model.id}"`);
}
}
break;
then I use it via a provider in my module:
providers: [{
provide: DYNAMIC_FORM_CONTROL_MAP_FN,
useValue: (model: DynamicFormControlModel): Type<DynamicFormControl> | null => {
switch (model.type) {
case MY_CUSTOM_DYNAMIC_FORM_CONTROL_TYPE_CONSTANT:
return MyDynamicCustomFormControlComponent;
}
}
}, {
provide: DYNAMIC_FORM_MODEL_MAP_FN,
useValue: (type: string, model: any, layout: any): DynamicFormControlModel | null => {
switch (type) {
case MY_CUSTOM_DYNAMIC_FORM_CONTROL_TYPE_CONSTANT:
return new MyDynamicCustomControlModel(model, layout);
}
}
}],
the custom model should define the inherited type field as serializable:
@serializable() readonly type: string =
MY_CUSTOM_DYNAMIC_FORM_CONTROL_TYPE_CONSTANT;
everything else is done by the docs
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#762 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQi9nJaL8vGziDg8ZTFYVn0EpmbxnU_3ks5va--SgaJpZM4UP8de>
.
|
@rockeshub: I am trying to integrate these changes into my repo asap.
|
Thank you
…On Fri, 29 Mar, 2019, 7:34 PM danielleiszen, ***@***.***> wrote:
@rockeshub <https://github.com/rockeshub>: I am trying to integrate these
changes into my repo asap.
Thanks it's really helpful. Do u have this in any stackblitz or any github
repo. I am new to this lib and find it difficult where all to make the
changes
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#762 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQi9nFdAb2RvL1RTdLpbWP9UfCZ76xOrks5vbh1YgaJpZM4UP8de>
.
|
I'm not sure if this would work in my use case, as I need to inject helper services into the form service to resolve data for the custom form control models. Perhaps the custom logic added in this example could be implemented in an separate method on the DynamicFormService class, which could then be overridded in a subclass? |
Hi,
That's exactly what I did except that my custom map fn runs before the default fromJSON's switch Let me know what you think |
@ronnetzer - thanks for this solution! hope it will make it into the package.. it's a life saver for anyone relying on custom controls and fromJSON model. |
I'm submitting a
I'm using
Description
Hello, I'm trying to make a custom control but at some point, I didn't understand as well, if there is example it's good because the documentation not explains enough.
for the hard part I didn't get it is:
in corresponding DynamicFormControlModel what should we put
?The text was updated successfully, but these errors were encountered: