What is the proper way to set a default value for an MVC wid

Posted by Community Admin on 04-Aug-2018 16:05

What is the proper way to set a default value for an MVC widget's property?

All Replies

Posted by Community Admin on 30-Jun-2014 00:00

I have an MVC widget with two properties: one for the header of the widget and one for optional text below the header.

I'd like the properties to have default values when the widget is placed on a page but the user should be able to change or remove the properties' values as needed.

 I tried setting the property values in the controller constructor. This almost does what I need. When the widget is placed on a page, the properties' are set to the defaults. The user can also change the properties as needed. However, if the user removes a property's value (for example, in the optional property), then the property is then set to the default. I would prefer that the property have an empty value.

 Is there a property way to set a default value for an MVC widget's property? And is there a way to let a user set a property's value to an empty string even when it has a default?

Posted by Community Admin on 30-Jun-2014 00:00

I discovered that if I set a widget's property to a whitespace (via the widget designer), then the property will not reset to the default value.

Posted by Community Admin on 18-Aug-2017 00:00

While that's a workaround, that doesn't solve the issue. Unless you sanitize all your properties (by trimming whitespace) then whitespace is passed through, which can potentially cause issues.

Sitefinity/Progress team: Is there a way to properly set defaults for MVC widgets here?

This thread is closed