Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the datetime format for the extra properties? #9848

Closed
xuyae573 opened this issue Aug 18, 2021 · 1 comment
Closed

How to set the datetime format for the extra properties? #9848

xuyae573 opened this issue Aug 18, 2021 · 1 comment

Comments

@xuyae573
Copy link

  • Abp 4.4.0
  • Razor Pages
  • EF Core

I have added 2 DateTime into extra properties for the IdentityUser

`ObjectExtensionManager.Instance.Modules()
.ConfigureIdentity(identity =>
{
identity.ConfigureUser(user =>
{
user.AddOrUpdateProperty( //property type: string
"MemberStartDate", //property name
property =>
{
property.Attributes.Add(new DisplayFormatAttribute() { DataFormatString = "{0:yyyy/MM/dd/}" });
property.DefaultValueFactory = () => "";

                            //validation rules
                            property.Validators.Add(context =>
                            {
                                if (context.Value != null)
                                {
                                    var startDate = (DateTime) context.Value;
                                    var endDate =
                                        context.ValidatingObject.GetProperty<DateTime>("MemberEndDate");

                                    if (endDate < startDate)
                                    {
                                        var message = LocalizableString.Create<LMSResource>("InvalidStartDate").Name;
                                        context.ValidationErrors.Add(
                                            new ValidationResult(
                                                message,
                                                new[] { "extraProperties.MemberStartDate" }
                                            )
                                        );
                                    }
                                }
                            });
                }
                    );
                    user.AddOrUpdateProperty<DateTime>( //property type: string
                        "MemberEndDate", //property name
                        property =>
                        {
                            property.DefaultValueFactory = () => "";
                            //validation rules
                            property.Attributes.Add(new DisplayFormatAttribute() { DataFormatString = "{0:yyyy/MM/dd/}" });
                        }
                    );
                });
            });`

And I have added the display format attribute for these 2 DateTime properties as well, but seems it does not work in UI part?

image

@JadynWong
Copy link
Contributor

JadynWong commented Aug 18, 2021

https://github.com/abpframework/abp/blob/HEAD/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs

You can try add new DataTypeAttribute(DataType.Date).

Current version does not seem to support DisplayFormatAttribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants