Need guidance: How to use Angular Reactive forms in Storybook ? (FormGroup / FormArray / FormControl) #15602
Replies: 10 comments 17 replies
-
@cuznerdexter unfortunately I do not have any solution or good news for you :P but am in a same situation as you are. So I wanted to ask wether you have managed to solve the puzzle? |
Beta Was this translation helpful? Give feedback.
-
Is it possible to use formcontrol in a MDX file? |
Beta Was this translation helpful? Give feedback.
-
No trying get paid for what they want the dee or a job want me to do on them or they need help doing o what I saying |
Beta Was this translation helpful? Give feedback.
-
I am running into the same issue but don't seem to be able to get @DriLLFreAK100 solution to work. The component I am writing the story for is fairly complex and uses the NgxmatSelectSearchModule as well. Im curious if that might be causing my issues but the console.error, which is the same as the original posters, does not seem to point to it. Error:
|
Beta Was this translation helpful? Give feedback.
-
Issue still persist in Angular 15 + Storybook 7.0.2. Any of the proposed solutions/workarounds worked for me, so I did this:
And then this form can be used as |
Beta Was this translation helpful? Give feedback.
-
Related: #16855 |
Beta Was this translation helpful? Give feedback.
-
Using the custom
|
Beta Was this translation helpful? Give feedback.
-
I suspect that using the mapper is not a solution for Angular with FormGroup instances. |
Beta Was this translation helpful? Give feedback.
-
Here's a relatively light option using setters to allow for patching values as args. Just make sure you're building the form in the constructor and not in onInit, or Storybook will try to patch before the form is in place.
|
Beta Was this translation helpful? Give feedback.
-
Hi ! I had this annoying issue as well with my Form stories... But I found a trick which maintains a fully fonctionnal FormGroup (with valueChanges working properly) in stories 🎉 Storybook tries to stringify any args you pass to a component. const MY_FORM = new FormGroup({
a: new FormControl('A'),
b: new FormControl('B'),
})
// Tell JSON.stringify to serialize it as null > No circular dependency
// You could return any value you like though
MY_FORM['toJSON'] = () => null;
export const FormStory: Story = {
name: 'FormStory',
args: {
form: MY_FORM
},
}; Note that this would work for ANY object that circles when stringified |
Beta Was this translation helpful? Give feedback.
-
I am working on an Angular12 App (using NX, Storybook, Cypress, Jest & KendoUI).
It is a complex app with many unique reactive form based components.
I am stuck building Stories for any component that uses Reactive Form modules.
Even a basic reactive form with only 1 FormGroup and 1 FormControl breaks in my stories.
Can someone please advise how to use Reactive Forms in Storybook ? or is there a good tutorial ? (I have not found one so far).
Here is some example code to explain:
Beta Was this translation helpful? Give feedback.
All reactions