Copied to clipboard

Flag this post as spam?

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


  • Chen 39 posts 68 karma points
    Jul 17, 2014 @ 13:48
    Chen
    0

    Umbraco 7 MemberProperties

    I have just installed Umbraco 7.1.4 and created a MemberRegistration macro using the built-in template. However, there seems to be an issue with one of my custom properties (see below), which is a True/False datatype.

    When all the properties is rendered out it's rendered as textbox, When I type in "yes" in Opt In and try to save I get an error saying that "The input string is in wrong format". I take it's because the datatype is set to boolean in Umbraco? When I log in to Umbraco backoffice, I can see that a member has been created, but without all the custom properties data entered. 

    Is there a way to render the "Opt in" property as a checkbox? I tried to use Html.CheckboxFor but it's expecting boolean value, whereas registerModel.MemberProperties[i].Value returns string.

    I noticed that EditorTemplate was mentioned in the comment section, but I'm not sure how to create it and to use in this MemberProperties loop. 

     

    Any help would be greatly appreciated!

    Cheers!

    Chen

  • cole young 20 posts 41 karma points
    Aug 13, 2014 @ 22:16
    cole young
    0

    I am facing the exact same scenario.

    Anyone have a suggestion, please?

  • Ilya 18 posts 53 karma points
    Aug 20, 2014 @ 20:04
    Ilya
    0

    Chen, Cole - have you guys found a solution?

    Have the same problem and would appreciate any help/suggestion/idea on how to work wich custom properties.

    Umbraco returns all member's custom properties as strings. So you can easily show editors for them (which are textboxes by default), and umbraco would automatically update the values in this textboxes. But how can I show editors for other types? Is there any way to convert a custom property to some other type (bool, for example) and bind it in the same way as strings do?

    Hope anyone can point me where to start from. Thanks! 

  • cole young 20 posts 41 karma points
    Aug 20, 2014 @ 21:01
    cole young
    0

    I am still looking for a solution, but I have not thought of or found anything.

    I don't know how (or if) you can pass properties whose type is not text because of the way the builtin registration controller was built.  

    I have had two suggestions from my team.  One is to write our own controller using the new member api to handle the back end.  The other was hide the non string member and to visually replace it with the expected form element, then use javascript/jquery to update the hidden form member when the visible one is changed.

    For option one, you can look at the source code for Umbraco's registration controller for a starting place.

    For option two, i added a property of textbox which will only have a "0" or a "1" in it.  I used the html helper for textbox (Html.TextBoxFor) to place the input element on the page, then used jquery to hide it (it wouldn't hide by trying to set style="display:none;").  I added the checkbox to the form and some jquery to update the hidden textbox when the checkbox changed.

    Now that i describe it to someone else, i will probably go back and create our own controller for registration that can handle the boolean field.

  • Ilya 18 posts 53 karma points
    Aug 21, 2014 @ 18:39
    Ilya
    0

    Thanks for your reply, Cole.

    I've had similar thoughts, thinking of these two variants (or something like them).

    Anyway, I'm still trying to find a better solution based on the snippet (which really looks perfect).

    Of course I'll let you know here if I find something (hope you'll do the same).

  • Chen 39 posts 68 karma points
    Aug 22, 2014 @ 10:32
    Chen
    0

    Same here, after searching around I couldn't find a solution to this problem. I even created a custom EditorTemplate for the checkbox (instead of the default textbox one) and was able to render out the checkbox in my view with no issue. However, it doesn't save to the database from the front-end. When I updated the checkbox in Umbraco back office, the EditorTemplate was able to display the correct value. So it seems it is 'Get' only.

    I can't find the source link in my history, but I stumbled across a solution on Gist. There seems to be a SetValue method on Services.MemberService. I guess you could do something like this:

    public ActionResult MemberRegister(RegisterModel model)

            {

                if (!this.ModelState.IsValid)

                {

                    return this.CurrentUmbracoPage();

                }

     var ms = Services.MemberService;

    var member = ms.CreateMember(
    model.Email,
    model.Email,
    model.Name,
    "Member");

    if (member.HasProperty("optIn")) { member.SetValue("optIn", model.OptIn); }

    memberService.Save(member);

    memberService.SavePassword(member, model.Password);

    memberService.AssignRole(member.Id, this.MemberGroupName);

    }

     

    I've not tested this so not sure if it works.

    Chen

Please Sign in or register to post replies

Write your reply to:

Draft