Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Question: Adding custom selectors in datatypes to display multiple field values per line in dropdowns.

$
0
0
I have two datatypes…
  • The first “Subjects” datatype has three fields: Id, SubjectLevel (data reference), SubjectName (string 64 – used as title field in lists). The SubjectLevel field has one of two values: “undergraduate” and “postgraduate”, and is used to distinguish between “Undergraduate Art” and “Postgraduate Art”
  • The second “Courses” datatype has many fields, including two Subject (data reference) fields. A course can be made up of one or two subjects.
Normally, I’d use a field type of “Data Reference” for the Subject fields in the “Courses” datatype, linking to the “Subjects” datatype. However, in this case the dropdown list will only show:
  • Art
  • Art
  • Design
  • Design
This is confusing, as there is no way to distinguish between those items in the form.

So, I had an idea... Maybe I should change the Subject fields in the “Courses” datatype from "Data Reference” to “Unique Identifier (GUID)” and use a “Selector” widget type under the advanced tab. Then I would link off to a custom XSLT function, instead of the automatically generated “GetSubjectsXml”. My new function contained the following template:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl in lang f">
    <xsl:template match="/">
        <xsl:if test="/in:inputs/in:result[@name='GetSubjectsXml']/Subjects">
            <SubjectsElements>
                <xsl:apply-templates select="/in:inputs/in:result[@name='GetSubjectsXml']/Subjects">
                    <xsl:sort select="SubjectLevel.EducationLevel" order="ascending" />
                </xsl:apply-templates>
            </SubjectsElements>
        </xsl:if>
    </xsl:template>
    <xsl:template match="/in:inputs/in:result[@name='GetSubjectsXml']/Subjects">
        <Subjects>
            <xsl:attribute name="Id">
                <xsl:value-of select="@Id" />
            </xsl:attribute>
            <xsl:attribute name="SubjectName">
                <xsl:value-of select="@SubjectLevel.EducationLevel" />
                <xsl:text> - </xsl:text>
                <xsl:value-of select="@SubjectName" />
            </xsl:attribute>
        </Subjects>
    </xsl:template>
</xsl:stylesheet>
... which produces something clean like:
<SubjectsElements xmlns="http://www.w3.org/1999/xhtml">
    <Subjects Id="08b98af7-d72d-415b-8906-6a27d253b90b" SubjectName="Undergraduate  - Art"/>
    <Subjects Id="483a7fe9-8a9f-4c36-8024-e2c772bab932" SubjectName="Postgraduate - Art"/>
    <Subjects Id="95dabec6-69b7-4744-9f65-c048ec994cd2" SubjectName="Undergraduate  - Design"/>
    <Subjects Id="d2f291c3-4a1a-4cca-8cfa-f3986922ed8a" SubjectName="Postgraduate - Design"/>
</SubjectsElements>
This should allow me to have a dropdown with:
  • Undergraduate - Art
  • Undergraduate - Design
  • Postgraduate - Art
  • Postgraduate - Design
Unfortunately, you don’t appear to be able to link to a function in this way, even though when editing the field widget configuration, you get an “Insert > Function Markup” button.

Does anyone have any idea how to get this to work?

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>