Copied to clipboard

Flag this post as spam?

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


  • Elitenet 120 posts 468 karma points
    May 18, 2018 @ 16:48
    Elitenet
    0

    Register Member snippet problem

    Hi Folks,

    I have used the Partial View snippet for register member. In the snippet it says:

      By default this will render a textbox but if you want to change the editor template for this property you can 
                        easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
                        create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to 
                        render your specific editor template like:
                        @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
    

    So I would like to know if anyone knows how to render values from a radio button list, and if the user has already selected something how to add it as preselected in Edit Member?

    thanks :-) /Peter

  • Amanda Ashley 22 posts 79 karma points
    May 19, 2018 @ 18:07
    Amanda Ashley
    1

    Following this as i actually have a use case for needing dropdowns.

    I was thinking of just making the front end with my own HMTL and copying the values into the Umbraco Fields (That would be hidden)

  • Elitenet 120 posts 468 karma points
    May 19, 2018 @ 22:24
    Elitenet
    0

    Hi Amanda, that would be the easiest solution for now.

    I found out that all the member properties are written as strings, so even if I used a HTMLhelper, the system cannot write the data, since it complains about "System.String cannot be cast as a Boolean"... something like that.

    So at the moment I am working on a total rewrite of the registercontroller, and editcontroller, so they can actually find the data from the datatypes and put them into the frontend. I have made a model solution with Boolean for checkboxes, next I need to find a way to access by DataTypeService, the data which comes from the backend to build both drop downs and radio buttons.

    But I wont be done with this just yet, might take a few weeks, so you should go with the javascript for now. I also need to study Members.GetCurrentMemberProfileModel() to see if I can use something from there.

    Guess this is a much needed feature for umbraco, no one really has had the time to solve.

  • Amanda Ashley 22 posts 79 karma points
    May 20, 2018 @ 06:03
    Amanda Ashley
    1

    Thanks @Elitenet

    Hopefully it is something that gets some attention by HQ.

    Going to go with the mixed aproach passing stuff around with jQuery and taking care of validation etc then giving the end result over to Umbraco to save.

    I've also noticed the the sort order of the member properties are not the order in which they are rendered.

  • Elitenet 120 posts 468 karma points
    May 20, 2018 @ 10:45
    Elitenet
    0

    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/59996-Member-Profile-Page

    In the end of this post, theres a guy who have hi-jacked the snippet and hardcoded the "registerModelMemberProperties5__Value" with some select boxes. You could maybe see if it's something for you. :-|

  • Amanda Ashley 22 posts 79 karma points
    May 21, 2018 @ 07:11
    Amanda Ashley
    1

    I have noticed that you can still change the rendered fields as per below.

    @Html.EditorFor(m => registerModel.MemberProperties[i].Value, new { htmlAttributes = new { @class = "form-check-input", @type = "checkbox" } })
    
    @Html.EditorFor(m => registerModel.MemberProperties[i].Value, new { htmlAttributes = new { @class = "form-control", @type = "date" } })
    

    And I have tested that having a Member field set to "date" dataType will save correctly if the Html.EditorFor field is set to "date".

    And to render things out in the order I wanted;

    @for (var i = 0; i < propertiesCount; i++)
    {
       if (@registerModel.MemberProperties[i].Alias == "testDate")
       {
           // Do some stuff
       }
     }
    
  • Amanda Ashley 22 posts 79 karma points
    May 21, 2018 @ 07:18
    Amanda Ashley
    1

    That way you can at least split out fields into different sections or do pretty much what you want.

    enter image description here

  • Elitenet 120 posts 468 karma points
    May 21, 2018 @ 10:04
    Elitenet
    0

    Okay, thats great news, its very helpful. Great work.

    Have you tried to make a checkbox with ie "Opt-in to Newsletter". I get an error with "Cant Cast Boolean to String", because it seems that the checkbox returns boolean, and the member property is written as a string. Maybe you can get it to work? Only if you have time to test.

    Cheers Peter

  • Elitenet 120 posts 468 karma points
    May 21, 2018 @ 13:29
    Elitenet
    0

    Hi Amanda, you dont have to test, I have tested it. The checkbox doesnt save the value.

    Also something funny, I found this in the controller:

     //TODO: Perhaps one day we'll ship with our own EditorTempates but for now developers 
    // can just render their own.
    

    So its something which was actually planned at some point.

  • Elitenet 120 posts 468 karma points
    May 21, 2018 @ 15:31
    Elitenet
    0

    I have create an issue, now please vote it up.

    http://issues.umbraco.org/issue/U4-11357

  • Amanda Ashley 22 posts 79 karma points
    May 21, 2018 @ 22:02
    Amanda Ashley
    1

    Up voted!

  • Amanda Ashley 22 posts 79 karma points
    May 21, 2018 @ 22:27
    Amanda Ashley
    2

    In the mean time to get around the checkbox issue for my consent checkbox I have done the following.

            // Consent
            $("#consentCheckBox").on('change', function () {
                var consentReceived = "true";
                    consentDeclined = "false";
    
                if ($(this).is(':checked')) {
                    $(".form-section-hide").show();
                    $('.field-consent-checkbox').val(consentReceived);
                    alert($('.field-consent-checkbox').val())
                }
                else {
                    $(".form-section-hide").hide();
                    $('.field-consent-checkbox').val(consentDeclined);
                    alert($('.field-consent-checkbox').val())
                }
            });
    

    And for the MVC Form fields I have left them as textboxes in the front end and in Umbraco. (Please note that I am using bootstrap material design checkboxes hence some of the markup).

                        if (@registerModel.MemberProperties[i].Alias == "consent")
                        {
                            <div class="col-md-6 push-top">
                                <div class="form-check @registerModel.MemberProperties[i].Alias">
                                    <div>
                                        <strong>@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name, new { @class = "bmd-label-static" }):</strong><br />
                                        <i>
                                            I consent to my data being collected so as to display my results in a graphacal format.<br />
                                            I understand that all of my data will be treated and secured as "sensitive"data.<br />
                                            No data will be shared with 3rd parties.<br />
                                            If data is later considered to be of benefit for future use to help the Trans* community, further consent will be sought.
                                        </i>
                                    </div>
                                    <label class="form-check-label">
                                        <input id="consentCheckBox" class="form-check-input" type="checkbox" value="" required data-validation-required-message="Consent is required to continue.">                                        
                                        <span class="form-check-sign">
                                            <span class="check"></span>
                                        </span>
                                    </label>
                                    <div class="hidden-field">
                                        @Html.EditorFor(m => registerModel.MemberProperties[i].Value, new { htmlAttributes = new { @class = "form-control field-consent-checkbox" } })
                                        @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
                                    </div>
    
                                </div>
                            </div>
                        }
    
  • Amanda Ashley 22 posts 79 karma points
    May 21, 2018 @ 22:34
    Amanda Ashley
    1

    It isn't a perfect solution but at least it's a property that can be easily checked / tested against.

    For my consent box i actually have it hide all other data fileds I have for registration and also the submit button unless it is checked. But the "false" value is still there to be added in as a fallback incase something goes weird with the JavaScript or someone does something dodgy.

    enter image description here

  • Sara 4 posts 94 karma points
    Jun 12, 2019 @ 11:28
    Sara
    0

    Hi Amanda,

    I was struggling with this checkbox issue too, and your solution saved me! :-)

    I even found how to render and correctly save the true/false value of the consent box.

    First, change the editor of the consent field to Checkbox (Property editor alias Umbraco.TrueFalse)

    consent checkbox editor

    Then, slightly edit your js code, like this:

    // Consent
        $("#consentCheckBox").on('change', function () {
           /******
            var consentReceived = "true";
                consentDeclined = "false";
           ******/
    
            // use int instead of string
            var consentReceived = 1;
                consentDeclined = 0;
    
            // same code here
            if ($(this).is(':checked')) {
                $(".form-section-hide").show();
                $('.field-consent-checkbox').val(consentReceived);
                alert($('.field-consent-checkbox').val())
            }
            else {
                $(".form-section-hide").hide();
                $('.field-consent-checkbox').val(consentDeclined);
                alert($('.field-consent-checkbox').val())
            }
        });
    

    The consent box will appear like this (mine is called "privacy", but it's the same thing):

    consent checkbox saved

    Hope it was helpful :-)

    Now I'll try to see if I can do the same thing with a field with Dropdown editor.

  • Elitenet 120 posts 468 karma points
    May 22, 2018 @ 10:52
    Elitenet
    0

    Great work. Now I will dive into making a custom controller and models for my project.

  • Amanda Ashley 22 posts 79 karma points
    May 23, 2018 @ 08:23
    Amanda Ashley
    0

    On another sidenote, but still related to Members. It would be great if we could:

    • Export Member DocTypes
    • Render Member Properties in the order they are sorted in their DocType (easily!),
    • Use "Nested Content" for a Member (Haven't tried this to see if it might work... but I have doubts that it does)
    • Export All Members from the Backoffice (Not just one at a time)
  • Amanda Ashley 22 posts 79 karma points
    May 25, 2018 @ 23:25
    Amanda Ashley
    0

    Actually the MemberService does expose a lot of this.

                    @{
                        var svc = ApplicationContext.Services.MemberService;
                        var member = svc.GetById(currentMember.Id);
                        foreach (var prop in member.Properties)
                        {
                            <p>Alias: @prop.Alias</p>
                            <p>Property Type: @prop.PropertyType.Name</p>
                            <p>Value: @prop.Value</p>
                            <p>Description: @prop.PropertyType.Description</p>
                            <hr />
                        }
                    }
    

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft