The 1C:Enterprise developers forum

#1
People who like this: 0 Yes / 0 No
Active user
Rating: 7
Joined: Jul 28, 2015
Company:

Hi everyone;

I have to add Form Items via code. In our configuration we have to develop creating survey as dynamic module. And I have to add Form Item as programmatically I mean via code. How can I do that? How can I add Form Item via code?

Edited: Mehmet Tuğrul SARIÇİÇEK - Nov 13, 2015 12:08 AM
 
#2
People who like this: 0 Yes / 0 No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Mehmet Tuğrul SARIÇİÇEK

Please see following examples:
Add a button to a form without of changing that form
How to create print forms dynamically

 
#3
People who like this: 0 Yes / 0 No
Active user
Rating: 4
Joined: Nov 19, 2012
Company:

Hi Mehmet Tuğrul SARIÇİÇEK,

Here is an example how to dynamically create buttons and input fields:

Code
   //Add new command and button
   ButtonCode = "NewButton";
   
   FormCommand = ThisForm.Commands.Add(ButtonCode);
   FormCommand.Action = "ButtonClick";
   FormCommand.Title = "ButtonClick";
   
   NewButton = Items.Add(ButtonCode, Type("FormButton"));
   NewButton.Type             = FormButtonType.UsualButton;
   NewButton.CommandName       = ButtonCode;
   NewButton.Title          = "Push me!";
   NewButton.Picture          = PictureLib.AddToFavorites; 
   NewButton.Representation    = ButtonRepresentation.PictureAndText;
   
   //add new input fields - checkbox and text input
   NewAttributes = New Array;
   NewAttributes.Add(New Structure("FieldCode,Type,Boolean", "FieldBoolean", New TypeDescription("Boolean"), True));
   NewAttributes.Add(New Structure("FieldCode,Type,Boolean", "FieldString", New TypeDescription("String"), False));
   
   AddDetails = New Array;
   
   For Each Page In NewAttributes Do
            
      Attribute = New FormAttribute(Page.FieldCode, Page.Type, , Page.FieldCode, True);
      
      AddDetails.Add(Attribute);
      
   EndDo;
   
   ThisForm.ChangeAttributes(AddDetails);

   For Each Page In NewAttributes Do
      
      Control = Items.Add(Page.FieldCode, Type("FormField"));
      Control.Type = ?(Page.Boolean, FormFieldType.CheckBoxField, FormFieldType.InputField);
      Control.DataPath = Page.FieldCode;
      
   EndDo;

 
#4
People who like this: 0 Yes / 0 No
Active user
Rating: 7
Joined: Jul 28, 2015
Company:

Hi Aleksey Bochkov,

Thank you so much

 
Subscribe
Users browsing this topic (guests: 3, registered: 0, hidden: 0)