+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Adding Custom Controls To Form Builder

Adding Custom Controls To Form Builder

71 posts, 0 answered
  1. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Mar 2011
    Link to this post
    Hi Duneel,

    You need to create a FieldControlDefinitionElement where you return DefaultFieldType - your custom control that inherits from FieldControl. Please check our Products sample catalog.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
  2. Peter Kinmond
    Peter Kinmond avatar
    11 posts
    Registered:
    22 Dec 2010
    15 Mar 2011
    Link to this post
    Hi Ivan,

    I've written a tutorial using the code from this thread which goes into more detail about all the parts of creating a custom form control:

    http://blog.falafel.com/blogs/peterkinmond/11-03-14/Creating_Custom_Form_Controls_in_Sitefinity_4_0.aspx

    Thanks,

    Peter

  3. Duneel
    Duneel avatar
    166 posts
    Registered:
    08 Dec 2010
    15 Mar 2011
    Link to this post
    Hi Peter,

    Thanks for the awesome tutorial. It's great!!

    Duneel
  4. Jean
    Jean avatar
    90 posts
    Registered:
    06 Nov 2008
    18 Mar 2011
    Link to this post
    Hi There,

    Is the a stable working production version of this? I require to setup forms with datetime picker control.

    Regards,
    Jean Erasmus
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Mar 2011
    Link to this post
    Hi Jean,

    You can use the code from the forum and polish it and Peter's solution which is very detailed ( thanks Peter)

    Greetings,
    Ivan Dimitrov
    the Telerik team
  6. Tony
    Tony avatar
    29 posts
    Registered:
    30 Dec 2010
    29 Jul 2011
    Link to this post
    Does anybody have a sample project that has an upload control working successfully? If so I would love to see how you went about making it happen. 
  7. Norman
    Norman avatar
    6 posts
    Registered:
    28 Jan 2011
    11 Nov 2011
    Link to this post
    Hi,

    We also have the same problem, same code that provided by this thread.  Just to provide more detail of the problem:

    1.  If you just drag the datepicker control in the form the first time, and edit it (e.g., add text to title, example), there is no problem and work fine.
    2.  Once the form saved, any subsequent edit, even without touching any properties in datepicker control, just to save it, and this will throw an error as below:

    "

    Server Error in '/' Application.


    Key cannot be null.
    Parameter name: key

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentNullException: Key cannot be null.
    Parameter name: key

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentNullException: Key cannot be null.

    Parameter name: key]

       System.Collections.Specialized.ListDictionary.get_Item(Object key) +7949573

       System.ComponentModel.PropertyDescriptorCollection.Find(String name, Boolean ignoreCase) +141

       Telerik.Sitefinity.Model.DataExtensions.SetValue(IDynamicFieldsContainer dataItem, String fieldName, Object value) +74

       Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl.SaveFormEntry(FormDescription description) +564

       Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl.ProcessForm(FormDescription form) +142

       System.EventHandler.Invoke(Object sender, EventArgs e) +0

       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154

       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691


    "
    3.  The error caused the form not useable, crashed the form.  You have to recreate the form without the datepicker to get it back to work again.
    4.  During the troubleshooting, I noticed that the first time you drag the datepicker control in the form, the field displayed normal (small field box, see first picture of attached file), but any subsequent edit, you will notice the datepicker field got expanded or displayed with large box (see 2nd picture attached), then save, and the problem.  What is changing that?  And that could be the root cause?

    Please shed some light, thanks!
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Nov 2011
    Link to this post
    Hi Norman,

    You can put a break point inside

    • Value
    • InitializeControls
    • SelectedDateChanged
    to see what is set when you try to save the control. It looks like that there is an empty data that goes to SetValue when you try to sav ethe form.

    Here is the code that is inside SetFormEntry. The problem is in the value that is passed to the highlighted line. You can put this method in your FormsControl and call it to see what exactly is going on.

    protected void SaveFormEntry(FormDescription description)
            {
                var manager = FormsManager.GetManager();
                FormEntry entry = manager.CreateFormEntry(String.Format("{0}.{1}", manager.Provider.FormsNamespace, description.Name));

                foreach (IFormFieldControl formFieldControl in this.formFieldControls)
                {
                    var field = formFieldControl as FieldControl;

                    var value = field.Value;

                    if (value is List<string>)
                    {
                        var cnv = new StringArrayConverter();
                        var v = cnv.ConvertTo((value as List<string>).ToArray(), typeof(string));
                        entry.SetValue(formFieldControl.MetaField.FieldName, v);
                    }
                    else
                    {
                        entry.SetValue(formFieldControl.MetaField.FieldName, value);
                    }
                }

                entry.IpAddress = this.Page.Request.UserHostAddress;
                entry.SubmittedOn = DateTime.UtcNow;
                entry.UserId = SecurityManager.GetCurrentUser().UserId;
                if (AppSettings.CurrentSettings.Multilingual)
                {
                    entry.Language = CultureInfo.CurrentUICulture.Name;
                }
                // TODO: find better way to keep autoincrement numbres in OA
                this.FormData.FormEntriesSeed++;
                entry.ReferralCode = this.FormData.FormEntriesSeed.ToString();
                manager.SaveChanges();
            }
    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Steven
    Steven avatar
    12 posts
    Registered:
    13 Jul 2012
    26 Apr 2012
    Link to this post
    I tried to implement Peter's code and it works great, up to a point. I can enter data in the textbox and submit and the values are showing up in the database, but when I try to view the responses in the backend, I get an "Object reference not set to an instance of an object." Here's the top of the error:
    [NullReferenceException: Object reference not set to an instance of an object.] Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.<GetScriptDescriptors>d__0.MoveNext()System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    Telerik.Sitefinity.Modules.Forms.Web.UI.FormsMasterDetailView.GetScriptDescriptors()
    System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl)
    System.Web.UI.ScriptManager.RegisterScriptDescriptors(IScriptControl scriptControl)
    Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.ViewBase.Render(HtmlTextWriter writer)
    I'm using Sitefinity 5.0. I'm not sure if that makes a difference or not but thought I should mention it.
  10. Steven
    Steven avatar
    12 posts
    Registered:
    13 Jul 2012
    26 Apr 2012
    Link to this post
    Sorry, double post because of site time out
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Apr 2012
    Link to this post
    Hi,

    You have to add the title to your form control

    public override string Title
           {
               get
               {
                   return "MyCustomFormsControl";
               }
           }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
71 posts, 0 answered
1 2 3