UI-O-Matic and setting default values

I’ve just released verison 1.7.0 which adds the ability to set default values by using the event model.

You can now attach to the event UIOMatic.Controllers.PetaPocoObjectController.ScaffoldingObject

Here is an example:

Say we have the following poco (with all of the UI-O-Matic stuff in place).

1 [UIOMatic("TestWithDate", "icon-users", "icon-user", RenderType = UIOMaticRenderType.List, 2 SortColumn = "TheDate", SortOrder = "desc")] 3 [TableName("TestWithDate")] 4 public class TestWithDate : IUIOMaticModel 5 { 6 public TestWithDate() 7 { 8 9 } 10 11 12 [UIOMaticIgnoreField] 13 [PrimaryKeyColumn(AutoIncrement = true)] 14 public int Id { get; set; } 15 16 [UIOMaticField("Firstname", "Enter your firstname")] 17 public string FirstName { get; set; } 18 19 [UIOMaticField("Lastname", "Enter your lastname")] 20 public string LastName { get; set; } 21 22 [UIOMaticField("TheDate", "Select a date")] 23 public DateTime TheDate { get; set; } 24 25 public IEnumerable<Exception> Validate() 26 { 27 28 return new List<Exception>(); 29 } 30 }

And we wish to set TheDate property to the current date time, you can now do that in the following way:

1 public class Startup : ApplicationEventHandler 2 { 3 protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) 4 { 5 UIOMatic.Controllers.PetaPocoObjectController.ScaffoldingObject += PetaPocoObjectController_ScaffoldingObject; 6 } 7 8 private void PetaPocoObjectController_ScaffoldingObject(object sender, UIOMatic.ObjectEventArgs e) 9 { 10 if (e.Object.GetType() == typeof(TestWithDate)) 11 ((TestWithDate)e.Object).TheDate = DateTime.Now; 12 } 13 }

So by using the event model, subscribe to the ScaffoldingObject event, and the in the eventhandler check the type of object (since this is executed for each type), and then simply cast to the correct type and set the property(or multiple) you would like to have a default value for.

6 Comments so far

  1. Laszlo on February 26th, 2016

    Thanks Tim, makes sense

  2. Laszlo on February 27th, 2016

    Tim, I have noticed after installing the new version the ScaffoldingObject event does not come up in Visual studio as it should.

  3. Biagio Paruolo on March 29th, 2016


    Is there a method to export data from backend?

  4. Erick on May 16th, 2016

    Awesome…! I have been working in umbraco 7 these days and luckly I found your packages! Awesome job! I would like to format a datetime column in a listview, I checked this link and I follow the source in github but I could find the right way to use it in my petapoco classes, any help?

  5. rajesh on November 13th, 2017


    can anyone suggest me, how to set the default values in uio-matic, Is there any dynamic method to hide the some of values.

  6. rajesh on November 13th, 2017


    when i have given


    the type or namespace name uiomaticIgnorefieldAttribute could not be found(are you missing using directive or an assembly reference?) it is showing like this.

    can anyone suggest how to ignore the some of values.

Leave a Reply