Copied to clipboard

Flag this post as spam?

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


  • Mike Coates 5 posts 25 karma points
    Apr 16, 2010 @ 18:23
    Mike Coates
    0

    Contour custom field type

    Hi all, I am attempting to extend the checkboxlist control to enable me to add extra attributes to a listitem (such as an alias or tag) for interrogation by code when a Contour form is submitted - ( I am looking to create a rule engine based on these extra attributes rather than the actual text entered as listitems in the standard checkboxlist control).

    I have tried a few things but Contour does not seem to like much. My last effort was to simply have a string replacement so that a user could enter an item such as: "I am interested in your product A [[prodA]]" where the extra bit at the end will be grabbed and set as an attribute of the list item. The code to do this should work programmatically but does not seem to have an effect so I was wondering if Contour does something "interesting" on the editor rendering and item storage...? Maybe someone has tried the same and can point me in the right direction or can point out a glaring error in this approach?

    Any help would be greatly appreciated.  

    Thanks

    Mike

  • Comment author was deleted

    Apr 17, 2010 @ 10:47

    Hi Mike,

    If you share your code I could take a look at what is going wrong.

    Cheers,
    Tim

  • Mike Coates 5 posts 25 karma points
    Apr 18, 2010 @ 22:00
    Mike Coates
    0

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Hi Tim,

    Thanks for taking a look...

    Here goes!  (sorry it looks odd - seems to do some interesting formatting when I paste from VS. )

    I hope this makes sense - this is my attempt to split the text value for the checkbox list item into two parts (value and alias) so that the alias can be stored as an attribute of the item.

     

    public class OWorkflowCheckboxList : FieldType

    {

     

    private OWFCheckboxList cbl;  //A custom extended checkboxlist control where I attempted to split the checkbox item text into 2 parts as in this code also.

     

    private List<object> _value;

     

    public OWorkflowCheckboxList()

    {

     

    this.Id = new Guid("9255717A-BE66-4835-87DF-8B86CE3CA7C4");

     

    this.Name = "OWorkflowCheckBoxList";

     

    this.Description = "Renders a checkbox list with aliases and assignment categories.....or so I hoped!";

     

    this.Icon = "checkboxlist.png";

     

    this.DataType = FieldDataType.String;

    _value =

    new List<object>();

    }

     

     

    public override List<object> Values

    {

     

    get

    {

     

    if (cbl != null && cbl.SelectedIndex > -1) {

    _value.Clear();

     

    foreach (System.Web.UI.WebControls.ListItem item in cbl.Items) {

     

    if

    (item.Selected)

    {

    _value.Add(item);

    }

    }

    }

     

    return _value;

    }

     

    set

    {

    _value =

    value;

    }

    }

     

    public override System.Web.UI.WebControls.WebControl Editor

    {

     

     

    get

    {

    cbl =

    new OWFCheckboxList();

    cbl.CssClass =

    "checkboxlist";

    cbl.RepeatLayout = System.Web.UI.WebControls.

    RepeatLayout.Flow;

     

    if (this.AssociatedField.PreValueSource != null)

    {

     

    foreach (var prevalue in this.AssociatedField.PreValueSource.Type.GetPreValues(this.AssociatedField))

    {

     

    string value = Umbraco.Forms.Data.DictionaryHelper.GetText(prevalue.Value);

    System.Web.UI.WebControls.

     

    ListItem item = new System.Web.UI.WebControls.ListItem(GetItemValue(value), GetItemAlias(value));

    item.Attributes.Add(

    "Alias", GetItemAlias(value));

    //try this too

     

    if

    (_value.Contains(GetItemValue(value)))

    item.Selected =

    true;

    cbl.Items.Add(item);

    }

    }

     

    return cbl;

    }

     

    set

    {

     

    base.Editor = value;

    }

    }

     

     

    public override string

    RenderPreview()

    {

     

    return "<div class=\"owfcheckboxlist\"></div>";

    }

     

    public override string RenderPreviewWithPrevalues(List<object> prevalues)

    {

     

    StringBuilder sb = new StringBuilder();

    sb.Append(

     

    "<div class=\"owfcheckboxlist\">"

    );

     

    foreach (var prevalue in prevalues)

    {

     

    sb.Append(

     

    string.Format("<p><input type='checkbox' alias='{0}'/> <label>{1}</label></p>"

    , GetItemAlias(prevalue.ToString()), GetItemValue(prevalue.ToString())));

    }

    sb.Append(

     

    "</div>"

    );

     

    return

    sb.ToString();

    }

     

     

    public override bool

    SupportsPrevalues

    {

     

    get

    {

     

    return true;

    }

    }

     

     

     

    private string GetItemValue(string value)

    {

     

    return

    SplitValue(value)[0];

    }

     

    private string GetItemAlias(string value)

    {

     

    return

    SplitValue(value)[1];

    }

     

    private string[] SplitValue(string

    value)

    {

     

    string[] retStr = new string[2];

     

    int startDelimiter = value.IndexOf(DELIMITERSTART);

     

    if

    (startDelimiter >= 0)

    {

     

    int endDelimiter = value.IndexOf(DELIMITEREND, startDelimiter);

     

    if

    (endDelimiter > 0)

    {

    endDelimiter +=

    DELIMITEREND.Length;

    retStr[1] = value.Substring(startDelimiter, endDelimiter - startDelimiter);

    retStr[0] = value.Remove(startDelimiter, endDelimiter - startDelimiter);

    }

     

    else

    {

    retStr[0] = value;

    retStr[1] =

    string.Empty;

    }

    }

     

    else

    {

    retStr[0] = value;

    retStr[1] =

    string.Empty;

    }

     

    return

    retStr;

  • Comment author was deleted

    Apr 19, 2010 @ 17:47

    Thanks Mike, will take a detailed look and come back to you with more info.

  • Mike Coates 5 posts 25 karma points
    Apr 21, 2010 @ 13:43
    Mike Coates
    0

    Any joy with this? cheers for taking a look though. Seems like an oversight not having a way to alias individual checkboxlist items or have them selectable in field-mapping control. :(

  • Mike Coates 5 posts 25 karma points
    Apr 26, 2010 @ 10:38
    Mike Coates
    0

    Hi Tim, I don't suppose you have been able to take a look at this yet? Unfortunately it is rather holding things up on a custom contour workflow project that is already overdue. Any pointers would be very useful, Thanks, Mike

  • Comment author was deleted

    Apr 26, 2010 @ 11:41

    Hi Mike,

    So depending on the choice made in the checkboxlist you want to execute a different action in the workflow?

    Can't you simply base the condition on the value?

  • Mike Coates 5 posts 25 karma points
    Apr 26, 2010 @ 12:21
    Mike Coates
    0

    Hi Tim, I will have to use the text if there is no other way  but the text of items will likely be altered and so having an alias or useful ID to link up with the rules engine would make more sense for maintainability. Cheers, Mike

  • Harald Ulriksen 207 posts 249 karma points
    Apr 28, 2010 @ 12:35
    Harald Ulriksen
    0

    Sort of missing the alias myself. 

Please Sign in or register to post replies

Write your reply to:

Draft