I'm trying to find some examples of Xpath used to select prevalues. "use current page as root" is almost enough for me but I need to filter out child nodes of current page based on some values. I'm hoping to be able to do it with Xpath but nothing seems to return anything.
I just realised it expects @id of the root node as a result of XPath. I was hoping it expects nodes to be used as prevalues. This is because i need to FILTER those nodes and this way... I don't think it is possible to filter.
Well, we solved it and here is the followup if anybody needs it. At the end we extended contour with custom prevalue source type. It is exactly the same prevalue source type as built-in "document" but we replaced "document type" dropdown with Xpath textbox. So, once you choose root node ... you can filter children of that node (by Xpath) to create prevalues.
This kind of looks like a good idea for the core module too since it is such a small change and very much like feature offered above for root node ("choose OR Xpath").
justa a short followup... another issue appeared from this. It seems umbraco uses @nodeName to populate prevalues. On the other hand, when form is filled and saved, daat stored is not @nodeName but content of selected node. So, if that node has many properties, resulting value got by using umbraco.contour:GetRecord() really has a mess of data.
On the other hand, when listing entries in back office of contour, there is @nodeName again. Maybe it is an issue with out modification of prevalues?
Does Contour 3.x allow for this scenario? Is there a way to pick prevalues based on an XPATH expression?
Mainly I just want a way to pick content that isn't a child but a decendent. Think of content in an auto-folder scenario where the alphabetical folders contain the content I want to pick in my drop down.
Currently, it works great in the scenario you have above. I get all my grandchildren and that will work. However, I was thinking it might be nice if it integrated with the Document Type dropdown selection to act as a filter.
For example, given this Content structure:
* A - Apple - Anise * B - Bok Choy
Where A and B are Folder DocTypes and their children are Produce DocType.
Could I set the Document Type drop down to Produce and then have the prevalue list be:
public class XPathPrevalueSource: FieldPreValueSourceType
{
[Setting("XPath", description = "Xpath to use", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
public string XPath { get; set; }
public XPathPrevalueSource()
{
this.Id = new Guid("74B9D0CE-F12C-499D-9E04-B1847336207F");
this.Name = "Umbraco Docs from xpath";
this.Description = "Uses nodes found by xpath";
}
public override List<PreValue> GetPreValues(Field field)
{
return uQuery.GetNodesByXPath(XPath).Select(node => new PreValue {Id = node.Id, Value = node.Name}).ToList();
}
public override List<Exception> ValidateSettings()
{
return new List<Exception>();
}
}
prevalues Xpath
I'm trying to find some examples of Xpath used to select prevalues. "use current page as root" is almost enough for me but I need to filter out child nodes of current page based on some values. I'm hoping to be able to do it with Xpath but nothing seems to return anything.
I just realised it expects @id of the root node as a result of XPath. I was hoping it expects nodes to be used as prevalues. This is because i need to FILTER those nodes and this way... I don't think it is possible to filter.
Anybody has an idea how to achieve this?
Well, we solved it and here is the followup if anybody needs it. At the end we extended contour with custom prevalue source type. It is exactly the same prevalue source type as built-in "document" but we replaced "document type" dropdown with Xpath textbox. So, once you choose root node ... you can filter children of that node (by Xpath) to create prevalues.
This kind of looks like a good idea for the core module too since it is such a small change and very much like feature offered above for root node ("choose OR Xpath").
Comment author was deleted
Awesome, yes would be good to include this, so instead of just selecting the parent with xpath you can also provide an xpath to select the nodes
justa a short followup... another issue appeared from this. It seems umbraco uses @nodeName to populate prevalues. On the other hand, when form is filled and saved, daat stored is not @nodeName but content of selected node. So, if that node has many properties, resulting value got by using umbraco.contour:GetRecord() really has a mess of data.
On the other hand, when listing entries in back office of contour, there is @nodeName again. Maybe it is an issue with out modification of prevalues?
Tim,
Does Contour 3.x allow for this scenario? Is there a way to pick prevalues based on an XPATH expression?
Mainly I just want a way to pick content that isn't a child but a decendent. Think of content in an auto-folder scenario where the alphabetical folders contain the content I want to pick in my drop down.
Thanks,
Jason
Comment author was deleted
Hi Jason,
Yes there is an Umbraco Documents prevalua source type that allows entering an xpath to select the parent node of the children you want to display.
Don't think it works with grandchildren but can make an update :) so it is possible
Comment author was deleted
Yup just checked the code and it only does children, will update with an option to move deeper
Comment author was deleted
Issue created and set to 3.0.7 release :) http://issues.umbraco.org/issue/CON-227
Awesome Tim!
I'll be watching for that release to come out and test it.
-Jason
Will the grandchildren change work with the simple node picker as well?
Thanks,
Jason
Comment author was deleted
Yup that's the plan :) eta this week
Comment author was deleted
A bit delayed but haven't forgotten, will be part of 3.0.7 coming later today
Tim,
The fast turnaround on this is epic. Thanks!
I have one idea to take it further:
Currently, it works great in the scenario you have above. I get all my grandchildren and that will work. However, I was thinking it might be nice if it integrated with the Document Type dropdown selection to act as a filter.
For example, given this Content structure:
* A
- Apple
- Anise
* B
- Bok Choy
Where A and B are Folder DocTypes and their children are Produce DocType.
Could I set the Document Type drop down to Produce and then have the prevalue list be:
Apple
Anise
Bok Choy
That would be awesome.
Anyways, thanks for a great package Tim!
-Jason
Comment author was deleted
Sure makes more sense that way, will give it a shot
Comment author was deleted
@Jason got a present for you :)
https://dl.dropbox.com/u/886345/Contour.AddonsForProWorks.zip just unzip and place in your bin dir
It's a new prevalue source that allows you to specify the nodes you want to include with an xpath expression
That should definlty do the trick for your scenario and a lot more... :)
Comment author was deleted
Pretty easy to create btw, using uquery
Tim,
#h5yr doesn't really do this justice. Beers at CodeGarden this year on me!
It worked perfectly! It even created the content on submission and linked to the node correctly. Sweet!
Thanks again for being awesome.
-Jason
is working on a reply...