Created a custom field prevalue source type that takes an XPath string and returns prevalues based on it.
Code:
public class GetValuesFromXpath : FieldPreValueSourceType
{
public GetValuesFromXpath()
{
this.Name = "Get Values from Xpath";
this.Id = Guid.NewGuid();
this.Description = "Gets prevalues from Xpath page headings";
}
[Umbraco.Forms.Core.Attributes.Setting("Xpath Value", description = "Xpath to get prevalues", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
public string XpathValue { get; set; }
public override List<PreValue> GetPreValues(Field field)
{
List<PreValue> result = new List<PreValue>();
try
{
List<Node> nodes = uQuery.GetNodesByXPath(XpathValue);
int sort = 0;
foreach (Node item in nodes)
{
PreValue pv = new PreValue();
pv.Id = item.Id;
pv.Value = item.Name;
if (field != null)
{
pv.Field = field.Id;
}
pv.SortOrder = sort;
result.Add(pv);
sort++;
}
}
catch (Exception ex)
{
Umbraco.Forms.Data.LogHelper.Error("Get values from xpath provider: " + ex.ToString());
}
return result;
}
public override List<Exception> ValidateSettings()
{
List<Exception> exceptions = new List<Exception>();
if (XpathValue.Trim().Length < 1)
{
exceptions.Add(new Exception("Xpath value must be supplied."));
}
return exceptions;
}
}
Created a prevalue Source with this custom source type with xpath value and prevalues were retrieved with a problem.
Added the new prevalue source to a form. Form worked fine.
Sometime between yesterday and today, no idea when or how, something got screwed up.
I notcied the form was no longer displaying. Navigating to the form in Contour displays an error:
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 241: copy</a> <a class="iconButton delete" href="#" onclick="javascript:DeleteField('<%# ((Umbraco.Forms.Core.Field)Container.DataItem).Id %>');">
Line 242: delete</a> <span class="handle">handle</span>
Line 243: <div class="fieldprevalues" style="display: none;" <%# GetPrevalueAttributes(((Umbraco.Forms.Core.Field)Container.DataItem)) %>>
Line 244: <asp:Repeater ID="rptPrevalues" runat="server">
Navigating to the prevalue source shows that the type is no longer selected. Even if I reselect the type and save, the error on the form does not go away.
Error with Custom Prevalue Source Type
Created a custom field prevalue source type that takes an XPath string and returns prevalues based on it.
Code:
Created a prevalue Source with this custom source type with xpath value and prevalues were retrieved with a problem.
Added the new prevalue source to a form. Form worked fine.
Sometime between yesterday and today, no idea when or how, something got screwed up.
I notcied the form was no longer displaying. Navigating to the form in Contour displays an error:
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 241: copy</a> <a class="iconButton delete" href="#" onclick="javascript:DeleteField('<%# ((Umbraco.Forms.Core.Field)Container.DataItem).Id %>');">
Line 242: delete</a> <span class="handle">handle</span>
Line 243: <div class="fieldprevalues" style="display: none;" <%# GetPrevalueAttributes(((Umbraco.Forms.Core.Field)Container.DataItem)) %>>
Line 244: <asp:Repeater ID="rptPrevalues" runat="server">
Line 245: <ItemTemplate>
Source File: d:\webroot\wec\usercontrols\umbracoContour\EditForm.ascx Line: 243
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Umbraco.Forms.UI.Usercontrols.EditForm.GetPrevalueAttributes(Field f) +394
ASP.usercontrols_umbracocontour_editform_ascx.__DataBind__control9(Object sender, EventArgs e) in d:\webroot\wec\usercontrols\umbracoContour\EditForm.ascx:243
System.Web.UI.Control.OnDataBinding(EventArgs e) +91
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +201
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
System.Web.UI.Control.DataBind() +15
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +127
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +478
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +61
System.Web.UI.WebControls.Repeater.DataBind() +76
Umbraco.Forms.UI.Usercontrols.EditForm.RenderFieldset(Object sender, RepeaterItemEventArgs e) +407
System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +115
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +138
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +478
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +61
System.Web.UI.WebControls.Repeater.DataBind() +76
Umbraco.Forms.UI.Usercontrols.EditForm.RenderPage(Object sender, RepeaterItemEventArgs e) +407
System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +115
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +138
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +478
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +61
System.Web.UI.WebControls.Repeater.DataBind() +76
Umbraco.Forms.UI.Usercontrols.EditForm.Page_Load(Object sender, EventArgs e) +989
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Navigating to the prevalue source shows that the type is no longer selected. Even if I reselect the type and save, the error on the form does not go away.
Comment author was deleted
Hey might be this line that is causing the issue:
Since the workflow will have a new guid each time the constructor is called ... so make sure this is a unique guid
is working on a reply...