Copied to clipboard

Flag this post as spam?

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


  • Pete 152 posts 176 karma points
    Jul 05, 2010 @ 13:40
    Pete
    0

    Identifying the step in RecordService.RecordPartiallySubmitted

    Is there a reference for the API for this? I've managed to get e.Form.Name from a very brief example I found but would love to see a full reference.

    Either way, how do I identify which step has just been submitted inside the RecordPartiallySubmitted event?

  • Pete 152 posts 176 karma points
    Jul 05, 2010 @ 15:46
    Pete
    0

    Right so I think I can identify the step by CurrentPageIndex (why is it called a step and a page? keep it simple!)

    The values in sender are for the _next_ step though??

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jul 05, 2010 @ 16:59
    Ismail Mayat
    3

    Pete,

    I have just managed to hack something together to indentify current page did you manage to pick up CurrentPageIndex? If so is that in the event RecordPartiallySubmitted.  

    Here is what I was trying to achieve.  I needed on top of my form a step bar eg step 1 > step 2 > step 3 for a multi step form where current page would be highlighted.  I couldnt see anything in api etc to do this.  So I did the following:  

    1. Created my own usercontrol that inherits from RenderForm

    2. Copied contents of renderform ascx over to my ascx.

    3. For next and prev button click events i added wire up extra delegates to handle events, this is where i add or substract current page from value stored in view state

    4. On init i check from view state current page and then for multipage form render out step captions of page.

    5. Updated the contour macro to point to my usercontrol from step 1

    My code looks like

    using System;
    using System.Web.UI;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Data.Storage;
    using Umbraco.Forms.UI.Usercontrols;
    namespace CogSteppedForm4Contour
    {
        public partial class ContourFormWithStepBar : RenderForm
        {
            private int CurrentPageIndex
            {
                get
                {
                    if (ViewState["pgv_pageindex"] == null)
                        ViewState["pgv_pageindex"] = 0;
                    return Convert.ToInt32(ViewState["pgv_pageindex"]);
                }
                set { ViewState["pgv_pageindex"] = value; }
            } 
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                b_next.Click += BNextClick;
                b_prev.Click += BPrevClick;
                SetUpStepBar();
            }
    
            private void SetUpStepBar()
            {
                using (var fs = new FormStorage())
                {
                    Form form = fs.GetForm(new Guid(this.FormGuid));        
                    if ((form != null) && (form.Id != Guid.Empty))
                    {
                        if(form.Pages!=null && form.Pages.Count>0)
                        {
                            pnlStep.Visible = true;
                            AddStepsToUl(form);
                        }
                    }
                }
            }
    
            private void AddStepsToUl(Form form)
            {
                int i = 0;
                formSteps.Controls.Clear();
                foreach(var page in form.Pages)
                {
                    string stepSelectedClass = "listItem";
                    if(i==CurrentPageIndex)
                    {
                        stepSelectedClass = "selected";
                    }
                    formSteps.Controls.Add(new LiteralControl(string.Format("<li class=\"{0}\">{1}</li>",stepSelectedClass,page.Caption)));
                    i++;
                }
            }
    
            void BPrevClick(object sender, EventArgs e)
            {
                CurrentPageIndex--;
                Trace.Write("ContourFormWithStepBar.b_prev_Click", string.Format("current page is {0}", CurrentPageIndex));
                SetUpStepBar();
            }
    
            void BNextClick(object sender, EventArgs e)
            {
                CurrentPageIndex++;
                Trace.Write("ContourFormWithStepBar.b_next_Click", string.Format("current page is {0}", CurrentPageIndex));
                SetUpStepBar();
            }
        }
    }

     

    I am going to write wiki on this mother of all hacks :-}

    Regards

     

    Ismail

     

  • Pete 152 posts 176 karma points
    Jul 05, 2010 @ 17:03
    Pete
    0

    Hi Ismail,

    I can't confirm yet whether ((RecordService)sender).CurrentPageIndex gives the correct step.

    Firstly, if it is correct it should be called "step" and not "page". Secondly, I've only got two steps at the moment and the int returned is 0, so I'd need to add a third step and test the value when moving from second to third. 

    I'm also concerned that (Record)((RecordService)sender) contains the fieldset for the second step, not the first one. To me, the event is on partial submit of a record so it should contain the partially submitted record of the first step, not the second step which we haven't even hit yet!

  • Pete 152 posts 176 karma points
    Jul 05, 2010 @ 17:04
    Pete
    0

    Ps. I will have a look through your code later when I have more time - looks good though :)

  • Harald Ulriksen 207 posts 249 karma points
    Jul 07, 2010 @ 13:36
    Harald Ulriksen
    0

    Ismail - great. Thanks for sharing.

  • Dev 8 posts 28 karma points
    Apr 24, 2012 @ 09:25
    Dev
    0

    Many thanks for sharing. It solved my problem.

Please Sign in or register to post replies

Write your reply to:

Draft