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

ABP dynamic form adds default value to AbpInputTagHelper #4548

Closed
gdlcf88 opened this issue Jun 30, 2020 · 4 comments
Closed

ABP dynamic form adds default value to AbpInputTagHelper #4548

gdlcf88 opened this issue Jun 30, 2020 · 4 comments
Assignees
Milestone

Comments

@gdlcf88
Copy link
Contributor

gdlcf88 commented Jun 30, 2020

The first way:

    public class CreateEditProductViewModel
    {
        [DefaultValue("Default")]
        public string Name { get; set; }
    }

The second way:

    public class CreateEditProductViewModel
    {
        public string Name { get; set; } = "Default";
    }

I thought the Name input box to use the default value on the creation modal page, but not really, neither of the above two ways worked.

@gdlcf88 gdlcf88 changed the title AbpDynamicForm adds default value to AbpInputTagHelper ABP dynamic form adds default value to AbpInputTagHelper Jun 30, 2020
@hikalkan
Copy link
Member

Can you share your full code class (you may need to create new CreateEditProductViewModel in the Get method)

@gdlcf88
Copy link
Contributor Author

gdlcf88 commented Jul 1, 2020

(you may need to create new CreateEditProductViewModel in the Get method)

I think that's why the problem happened.

I try to create CreateEditProductViewModel manually, it works:

    public class CreateEditProductViewModel
    {
        public string Name { get; set; } = "Default";
    }

    public class CreateModalModel : MyProjectPageModel
    {
        [BindProperty]
        public CreateEditProductViewModel ViewModel { get; set; } = new CreateEditProductViewModel(); // this way works.

        // .ctor

        public virtual Task OnGetAsync()
        {
            ViewModel = new CreateEditProductViewModel();  // or this way.
            
            return  Task.CompletedTask;
        }
    }

There are some questions:

  • The document's demo does not create a new model, should it be updated?
  • Should the default value works if the model is not assigned a value?
  • Should the DefaultValueAttribute also be able to provide the default value?

@yekalkan
Copy link
Member

yekalkan commented Jul 7, 2020

Hi,

It seems like creating a new instance of the model in OnGet method is required. I couldn't find any other way to make it work with Name { get; set; } = "Default"; usage.

Should the default value works if the model is not assigned a value?

No. But it would be nice.

Should the DefaultValueAttribute also be able to provide the default value?

It doesn't provide for default AspNet Core input tag helper.

The document's demo does not create a new model, should it be updated?

It doesn't use any default value, so no need to initialize a new model in OnGetAsync.

@yekalkan yekalkan closed this as completed Jul 7, 2020
@jonny-xhl
Copy link

(you may need to create new CreateEditProductViewModel in the Get method)

I think that's why the problem happened.

I try to create CreateEditProductViewModel manually, it works:

    public class CreateEditProductViewModel
    {
        public string Name { get; set; } = "Default";
    }

    public class CreateModalModel : MyProjectPageModel
    {
        [BindProperty]
        public CreateEditProductViewModel ViewModel { get; set; } = new CreateEditProductViewModel(); // this way works.

        // .ctor

        public virtual Task OnGetAsync()
        {
            ViewModel = new CreateEditProductViewModel();  // or this way.
            
            return  Task.CompletedTask;
        }
    }

There are some questions:

  • The document's demo does not create a new model, should it be updated?
  • Should the default value works if the model is not assigned a value?
  • Should the DefaultValueAttribute also be able to provide the default value?

So you need to initialize instances?

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

No branches or pull requests

4 participants