Create form field dynamically

Create form field dynamically

  

I have an entity with about 50 attributes and which attributes are shown up in a form is dependent on a parameter. As the attrbutes are so many, i don"want to drag all in the form and manipulate the visible property. So, i am thinking to create fields in the form dynamically. Is it possible? Tq

Hi Anonymous,

This isn't possible, unfortunately. I could think of a number of ways to solve this, but I'm not sure what your use case is exactly?

Thank u Sir,

Here is the case in the real world project i got involved now:

-  in multifinance we need to record collaterals

- there are so many collateral types and they have some common attributes and also some uncommon attributes

- instead of creating entity for each collateral type, i create an entity that contains all attributes of the collaterals.

- in the form entry of course it displays the attributes that corresponds to a specific collateral type. 

- so i create another entity to specify which attributes belong to which collateral type.

- The attrbutes can be of any data types : duedate (date), collnumber (text), amount(currency), etc.

-  and then i stuck to create this kind of dynamic form.

Best regards,

A


The entities are something like this:

CollEntity(

CollType text

Attr1 currency,

Attr2 date,

Attr3 text

)

CollAttributeEntity(

CollType text,

AttrName text,

AttrDataType text

)

Say it collateral of  type A has only two attrbutes Attr2 of data type date and Attr3 of data type text, the form should displays only these two attributes. So there are two form fields of those types.

The number of the attributes is about 50, so i do not want to put/drag them all  in a form and just do trick by display/hide them.


Tq

Well, there's no easy way out here. You could of see what the largest set of different attributes types is you'll ever going to need, and map the fields to the attibutes used. Or you could make web blocks for each of the most common types of combinations of attributes, so you'll end up with multiple forms.

But a fully dynamic set of properties on some entity will be difficult to capture. It'll always be a not-so-nice solution.

Solution

You can try show/hide fields in the form based on your collateral type by adding some mapping like which fields to show for a particular collateral type. But in this approach there is a disadvantage, you need to create the form with all fields of entity and add logic to show hide based on your collateral type. and you need to render all fields into the form.


Thanks,

Sivaramakrishna Repalle

Solution

sivaramakrishna repalle wrote:

You can try show/hide fields in the form based on your collateral type by adding some mapping like which fields to show for a particular collateral type. But in this approach there is a disadvantage, you need to create the form with all fields of entity and add logic to show hide based on your collateral type. and you need to render all fields into the form.


Thanks,

Sivaramakrishna Repalle

Yes, this is the last technique i did (although i said this is not what i want to in the last posting) as there is no else. 

1. Drag all attributes to create fields in a form

2. In the each form field container's visibility, put a server function whether to show or hide it.

3. On the combo box of the collateral type"s change event, just do ajax refresh of the fields' container mentioned above.

Thank you and best regard,

A