cloudscribe/cloudscribe.UserProperties.Kvp

DisplayName KVP works on registration, but subsequent changes are ignored

Closed this issue · 7 comments

cloudscribe/cloudscribe#346 described how we can use a custom registration property to allow the user to specify their Display Name. This works nicely. Example settings for this property:

          {
            "Key": "DisplayName",
            "Label": "Display Name",
            "EditPartialViewName": "FormItemInputPartial",
            "ReadOnlyPartialViewName": "FormItemLabelPartial",
            "Tooltip": "This will be your visible name on the website. If not entered, the first part of your email will be used.",
            "DefaultValue": "",
            "CssClass": "lastname",
            "IconCssClass": "far fa-user",
            "IconOnLeft": "true",
            "VisibleOnRegistration": "true",
            "VisibleToUserOnProfile": "true",
            "EditableByUserOnProfile": "true",
            "VisibleOnAdminUserEdit": "true",
            "EditableOnAdminUserEdit": "true",
            "MaxLength": "100",
            "MaxLengthErrorMessage": "Display Name has a max length of 100 characters",
            "Required": "false",
            "RequiredErrorMessage": "Display Name is required",
            "RegexValidationExpression": "",
            "RegexErrorMessage": "",
            "Options": []
          }

but, if the user then edits this Display Name on the /manage/userinfo page, it is ignored, and doesn't update the core DisplayName property.
If it updates it the first time it would be best if it did every time, if possible.

@joeaudette possible to make edits to this KVP property update the core property in the same way it does on registration?

This looks like a bug in the kvp here:
https://github.com/cloudscribe/cloudscribe.UserProperties.Kvp/blob/master/src/cloudscribe.UserProperties.Kvp/UserPropertyService.cs

This method is missing the DisplayName case which should return true:

public bool IsNativeUserProperty(string key)
    {
        switch(key)
        {
            case "FirstName":
            case "LastName":
            case "DateOfBirth":
            case "AuthorBio":
            case "Signature":
            case "Gender":
            case "AvatarUrl":
            case "WebSiteUrl":

                return true;
        }
        return false;
    }

Thanks Joe that makes sense. I'll pass this on to Jim to fix and release.

@CrisipnF I want to transfer this issue into the cloudscribe.UserProperties.Kvp repo, but github won't let me :(

update package cloudscribe.UserProperties.Kvp to 4.0.1

Any KVP field that is also a native user field will be shown twice on the admin's user edit screen (with unpredictable results on user update/save) unless in the config you set:

            "VisibleOnAdminUserEdit": "false",
            "EditableOnAdminUserEdit": "false",

Confirming what Simon says above - at the moment the UI can go a bit awry if you try to declare KVP properties that duplicate existing native User fields.

This comes down to a difference between how the administrator's User Management forms handle things -
'New User' behaves differently from 'Manage' (= edit user).

For the 'Manage' (user edit) screen, indeed you can get the same form input element twice (eg with DoB).

However, if you get rid of that by doing what Simon suggests above, setting the above config settings to false -
but if you have declared the KVP for DoB as 'required' -
then the admin's "New User" screen becomes impossible to submit, because it does not have its own pre-existing DoB input, the above config prevents the KVP DoB form input element being rendered, but the validation still kicks in.

So maybe a bit of work needed on those various user management forms, validation etc.

Spun out a separate ticket