Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Adam Prendergast 33 posts 77 karma points MVP c-trib
    Mar 09, 2012 @ 09:41
    Adam Prendergast
    0

    Custom FieldType not saving

    I have created a custom field tyep which is the same as the standard 'textfield' just with a different name. I have done this to target specific text fields with css.

     

    The form fails to save when the custom FieldType is implented.

     

    public class MonetaryTextField : FieldType
      {
        public List<object> Value;
        public MonetaryTextField()
        {
          Id = new Guid("57ADD3AB-C3CD-464D-BCC2-3D1C05D3BF65");
          Name = "Monetary Text Field";
          Description = "Adds monetary formating to the form field";
          Icon = "textfield.png";
          DataType = FieldDataType.String;
          Value = new List<object>();
        }
        public override string RenderPreview()
        {
          return "<input type=\"text\" />";
        }
        public override string RenderPreviewWithPrevalues(List<object> prevalues)
        {
          return RenderPreview();
        }
        public override WebControl Editor
        {
          get
          {
            System.Web.UI.WebControls.TextBox tb = new System.Web.UI.WebControls.TextBox();
            tb.TextMode = System.Web.UI.WebControls.TextBoxMode.SingleLine;
            tb.CssClass = "monetary-field";
            return tb;
          }
          set
          {
            base.Editor = value;
          }
        }
      }

     

     

    On submit I am getting:

     

    Object reference not set to an instance of an object.

    [NullReferenceException: Object reference not set to an instance of an object.]

       Umbraco.Forms.Data.Storage.RecordFieldValueStorage.InsertRecordFieldValues(RecordField rf) +677

       Umbraco.Forms.Data.Storage.RecordFieldStorage.InsertRecordField(RecordField recordfield) +1196

       Umbraco.Forms.Data.Storage.RecordStorage.InsertRecord(Record record, Form form) +1865

       Umbraco.Forms.Core.Services.RecordService.() +205

       Umbraco.Forms.Core.Services.RecordService.Submit() +39

       Umbraco.Forms.Core.Services.RecordService.NextPage() +169

       Umbraco.Forms.UI.Usercontrols.RenderForm.nextPage(Object sender, EventArgs e) +241

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

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

     

    What am I doing wrong? Any help would be appreciated.

  • Adam Prendergast 33 posts 77 karma points MVP c-trib
    Mar 09, 2012 @ 15:11
    Adam Prendergast
    0

    This is my fault for not reading the Developer Docs correctly the two correct method overrides are:

    public override WebControl Editor
        {
          get
          {
            tb.TextMode = System.Web.UI.WebControls.TextBoxMode.SingleLine;
            tb.CssClass = "text monetary-field";
    
            if (_value.Count > 0)
              tb.Text = _value[0].ToString();
    
            return tb;
          }
          set
          {
            base.Editor = value;
          }
        }
    
        public override List<Object> Values
        {
          get
          {
            if (tb.Text != "")
            {
              _value.Clear();
              _value.Add(tb.Text);
            }
            return _value;
          }
          set
          {
            _value = value;
          }
        }

Please Sign in or register to post replies

Write your reply to:

Draft