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?
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.
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.
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. :-|
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.
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>
}
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.
Register Member snippet problem
Hi Folks,
I have used the Partial View snippet for register member. In the snippet it says:
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
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)
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.
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.
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. :-|
I have noticed that you can still change the rendered fields as per below.
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;
That way you can at least split out fields into different sections or do pretty much what you want.
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
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:
So its something which was actually planned at some point.
I have create an issue, now please vote it up.
http://issues.umbraco.org/issue/U4-11357
Up voted!
In the mean time to get around the checkbox issue for my consent checkbox I have done the following.
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).
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.
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)
Then, slightly edit your js code, like this:
The consent box will appear like this (mine is called "privacy", but it's the same thing):
Hope it was helpful :-)
Now I'll try to see if I can do the same thing with a field with Dropdown editor.
Great work. Now I will dive into making a custom controller and models for my project.
On another sidenote, but still related to Members. It would be great if we could:
Actually the MemberService does expose a lot of this.
is working on a reply...