Skip to content
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

Dynamic Form Fields #6260

Open
rafaelmartinelli opened this issue Apr 15, 2024 · 0 comments
Open

Dynamic Form Fields #6260

rafaelmartinelli opened this issue Apr 15, 2024 · 0 comments

Comments

@rafaelmartinelli
Copy link

Hello,

I want to generate a form dynamically based on field descriptions in an array. Let's say an event with several participants, and the user may create some dynamic fields for each event. I am using an EAV Model with two classes FormFieldDescription which described the fields for each event, and FormFieldValue, which stores the value for each event and participant:

#[ORM\Entity(repositoryClass: EventRepository::class)]
class Event
{
    //...

    /** @var FormFieldDescription[] $fields */
    #[ORM\OneToMany(mappedBy: 'event', targetEntity: FormFieldDescription::class, orphanRemoval: true)]
    private Collection $fields;

    //...
}

#[ORM\Entity(repositoryClass: ParticipantRepository::class)]
class Participant
{
    //...
    #[ORM\ManyToOne(inversedBy: 'participants')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Event $event = null;

    #[ORM\OneToMany(mappedBy: 'participant', targetEntity: FormFieldValue::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $values;

    public __construct(Event $event)
    {
        $this->event = $event;
        foreach ($this->event->getFields() as $field)
            $this->addValue(new FormFieldValue($field, $this));
    }
    //...
}

When the user creates a participant, I want EA to display a form with the static fields, and the dynamic fields. I managed to display the dynamic fields using a CollectionField, however it looks ugly:

image

I would like to know a way to display them like regular fields, being able to configure them based on FormFieldDescription. Is it possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant