Change field required dynamically base on user select in Symfony 4 Form - forms

i need my app require(true/false) a title(TextType) based on what select from 'event' field(ChoiceType) in a single form.
So, how can i modify my 'title' base on what user select on 'event' dynamically?

How to dynamically Generate Forms Based on user Data
https://symfony.com/doc/current/form/dynamic_form_modification.html#how-to-dynamically-generate-forms-based-on-user-data
Add the EventListener on your ChoiceType.

Related

Symfony2.8 ChoiceType form filed with TextType form field

In Symfony 2.8 when I edit or create a user, I create the UserType form to render all fields.
The UserType form has an Roles field which I get all roles and render it like checkbox.
The question is our boss want to add an input field at every each roles on the right.
The red color I marked section is the needed input section
.
In this way our boss can edit the input text box so that he can see more clearly every role's meaning.
How can achieve this?
One solution is to move Roles to DB and store them as other entities. In such scenario you will need Role entity with at least two properties:
name
description

Generate custom Azure web form

I am working on Azure C# project. There is webrole with web form collecting customer’s information.
Depending on the information, they submit I need to create new custom web form for each one of them.
How can I generate new web form with custom web controls inside same site with code? I would prefer not create different site for each customer.
Any ideas appreciated!
You don't have to create a custom web form for each customer, you can have it all in on dynamic form and draw the input controls according to the customer.
You will have to have a form a form or a database table to configure the input needed for each customer which will be used in drawing the form.
ex:
You can have a table named: CustomerAttibute with the following columns
Customer ID
Attribute Name
Attribute Type (Number, text, boolean, ...)
Is Required
Validation Reg Expression
In the web form, you will read the customer ID and retrieve the attributes related to that customer, and use these attributes to draw the form, ex: an attribute of type text will be rendered as a textbox but an attribute of type boolean will be rendered as a checkbox
Capture the values from the user and insert it into another table, ex: CustomerAttributeValue which will have the attribute ID and attribute value, the value will be string to accommodate for any type

How can I create a Symfony form base class for fields used on every entity?

I'm trying to come up with a way to create a 'base form' that contains fields used on every entity, i.e. id, created_at, updated_at, etc.
I want to either extend the base form when I create a new form or easily include it in each new form I make. I can't find much documentation on it, is this a common thing to do?

How to handle autopopulated selects (from oneToMany relation) in Symfony form?

I have a ProductCategory class that has a parent and some children, properly annotated using Doctrine.
Then I have a ProductCategoryType (form class) that I use to render the html form.
Doctrine does its magic and creates a select box for parent which consists of previously added categories.
My problem: How to I prepend a default option (say '0' => 'No parent category') and how do I remove a particular category from list (ex: the currently edited category, so user can't select the very category to be its own parent)?
This can easily be achieved by using DataTransformers.
You can find more information in the documentation chapter How to use Data Transformers.

CakePHP - Automatically populate form fields from model

I thought the form helper did this already, but can the fields in my form automatically be populated with values from the model or do I have to set them all as template variables and set them all as the value of each field manually?
The form is for a user profile, so I just want it to put the user's names, email, etc in the correct form fields automatically.
for example: in controller $this->data = $this->Model->find('first',array(...));
in view:
$this->Form->create('Model');
$this->Form->input('field1');
...
$this->Form->end('Save');