Copied to clipboard

Flag this post as spam?

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


  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 28, 2013 @ 01:50
    Kris Janssen
    1

    "Dynamic" PrevalueSource from form records

    Hi,

    I have a form where users enter data. The records of this form are nicely stored and I can pull them into a custom PrevalueProvider like so:

    public class GetValuesFromAppRecords: FieldPreValueSourceType
    
    [Umbraco.Forms.Core.Attributes.Setting("AppRecords", 
            description = "Records containing applicant information", 
            control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist",
            prevalues = "OPT 1,OPT 2,OPT 3,OPT 4,OPT 5,OPT 9")]
        public string Position { get; set; }
    ...some more code here...
    public override List<PreValue> GetPreValues(Field field)
        {
            List<PreValue> _lResult = new List<PreValue>();
    
            try
            {       
                RecordStorage rStor = new RecordStorage();
                foreach (Record record in rStor.GetAllRecords(new Guid("guid-as-string"))) 
                {
                    if (record.RecordFields.Where(f => f.Value.Field.Caption == "somestring").First().Value.ValuesAsString() == Position)
    ... more code here ...
    

    So basically, I get records, submitted through another form and I filter them based on the value of Position.

    This runs fine (if a bit slow because there are quite a few records) and I could use the contour designer using this Prevalue Source to set up a new form featuring e.g. a checkboxlist...

    However, I would like to take this one step further...

    Instead of hard-coding the Prevalue Source settings I would ideally like to tune the Prevalue Source filtering on the fly, e.g. by first putting a drop down on my form, letting the user select a value and based on this value generate the correct Prevalues.

    This is quite different from most, if not all, examples where the pre value source is populated before being used on a form.

    The closest thing I can get now is to generate different prevalue sources based on my Prevalue Source Type, each time with a different setting for Position and likewise creating a form with many checkbox lists and conditional visibility but this is

    a) a lot of work, error-prone b) creates a lot of overhead since all the separate Prevalue Sources need to be generated for each form for each possible Position.

    Problem is, I do not see where I could set a property of my Prevalue Source Type at "runtime" based on other data entered into my form.

    Don't know if that makes sense?

    Any help is greatly appreciated.

  • Kris Janssen 210 posts 569 karma points c-trib
    Nov 28, 2013 @ 08:27
    Kris Janssen
    0

    Another situation where this might come in handy are polls where you want users to submit a e.g. a top 3 from a set of choices. Selecting one value in a listbox should prevent that same value from showing up in the following list boxes...

  • Comment author was deleted

    Nov 28, 2013 @ 10:58

    Hmm guess in that case it might be best to create a new fieldtype and don't worry about prevalue source, just add the logic in the fieldtype

  • Comment author was deleted

    Nov 28, 2013 @ 10:58

    For the second request that can easily be handles by some client side js

Please Sign in or register to post replies

Write your reply to:

Draft