Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 31, 2012 @ 10:24
    Matt Brailsford
    0

    Saving a single property to two fields in DEWD?

    Hey Guys,

    I'm using dewd to edit a custom entity, part of which requires a lat / lng coordinate saving. What I would like to do is use something like Darrens Google Maps DataType to allow them to select the location graphically, but when it saves, rather than saving the value as a coma seperated string in a single column, have it save the lat / lng to individual fields in the database. 

    Does anybody know if this is possible? and if so how? I can see it supports some events, but there doesn't seem to be much documentation around them, so I'm not sure if what I want to do is possible.

    Many thanks

    Matt

  • Mads Krohn 211 posts 504 karma points c-trib
    Oct 31, 2012 @ 10:31
    Mads Krohn
    0

    Hey Matt

    I might have something that can help you out, let me get back to you just a little later.

  • Sune Bøegh 64 posts 374 karma points
    Oct 31, 2012 @ 10:47
    Sune Bøegh
    0

    Hey Matt,

    Should be possible. Can you give some details on this custom entity? How are you saving changes to it currently (is it some activercord-style-thingy)?

    You're right about the missing event documentation, should do something about that :) You can attach events to an editor like this:
    <editor>
       <event name="BeforeSave" handler="MyNameSpace.MyType.MyMethod,MyAssembly" />
       ...
    </editor>
    And the handler method-signature should be like this:
    void BeforeSaveDoStuff(object sender, BeforeSaveEventArgs e)

    The event-args contains the dictionary of fields/values, which is later used by the main save method, so it can be modified as this point. Other supported events on the editor are: BeforeSave, AfterSave, BeforeDelete, AfterDelete

    - Sune 

  • Sune Bøegh 64 posts 374 karma points
    Oct 31, 2012 @ 10:50
    Sune Bøegh
    0

    @Mads Whups, missed your post :) Cool if you have an example on this.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 31, 2012 @ 10:53
    Matt Brailsford
    0

    Hey Sune,

    It's all early stages, so this is me just setting it up, so ideally it will all be saved using DEWD. That said, I do also have some PetaPoco repositories for modifying them aswell, but I don't think that is important.

    I've just managed to hookup a BeforeSave handler, and can see that you get access to the fields, so I will give that a try. If I do go that route, obviously, I should be able to split the value and save the lat / lng values to seperate fields, but what would you suggest being the best way to get the values back out such that the Google Maps DataType can use the value when editing (ie, merge them back together for the editor)? I tried using the format attribute and passing both fields into the sourceField attribute but that didn't work.

    Matt

  • Sune Bøegh 64 posts 374 karma points
    Oct 31, 2012 @ 11:10
    Sune Bøegh
    0

    Okay cool.

    Yeah, it would be nice with an editor-event which would allow the values to be changed just before rendering the controls/fields for that part. Anyway what you can definitely do is to inherit from the Editor-type you use eg. Eksponent.Dewd.Repositories.Table.TableEditor and override the GetRowValues method and change the values here. You can tell dewd to use the custom editor on the editor-tag, like so: <editor type="MyCustomEditorType">. You could attach the BeforeSave handler in the code as well, if you do this.

    It's just from the top of my head, there might be a more elegant way of doing this, so might post an update. Or maybe Mads has a neat solution coming :)

  • Mads Krohn 211 posts 504 karma points c-trib
    Oct 31, 2012 @ 11:11
    Mads Krohn
    0

    I did do something similar not that long ago, so yes, I might have something coming up :)

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 31, 2012 @ 11:13
    Matt Brailsford
    0

    Ok, so I've managed to get the following working (though it's not exactly how I want it to work).

    If I define fields in the editor for Latittude, Longitude and the combined property Location, I can setup a BeforeSave handler to grab the value from the Location field, split it, and put it's values into the Latitude and Longitude fields. A couple of things I would like to be able to do are:

    1) Don't show the actual Longitude and Latitude fields as they don't need to be visible. Unfortunately it seems they have to be defined to be able to save the values.
    2) I would need some way so that when the editor is re-opened, I can some how combine the lat / lng values again, to pass into the Location field so that it loads configured to the saved location.

    Anybody got any ieas on these?

    Many thanks

    Matt 

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 31, 2012 @ 11:22
    Matt Brailsford
    0

    Ok, sweet, so by implementing a custom TableEditor, I can override GetRowValues and combine the Lat / Lng values for the Location property. So the last thing is, is there a way to hide the actual Lat / Lng fields in the editor, whilst still being able to get / set the values? The only way I can think right now, is to maybe make a custom data type that is capable of hiding itself.

    Any other suggestions?

    Matt

  • Sune Bøegh 64 posts 374 karma points
    Oct 31, 2012 @ 11:25
    Sune Bøegh
    0

    Have you tried removing the umbracoDataType attribute on the lng/lat fields? So that the fields are there, but have no control. I'm fairly sure this works.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 31, 2012 @ 11:37
    Matt Brailsford
    0

    Hey Sune, just tried it now. It seems like I can access the values of the Lat / Lng fields during GetRowValues, which is great, but I don't seem to be able to save the values when I override the Save method.

    During the save method, the lat / lng values aren't in the list of values so I tried adding them to it, but no luck.

    Any other ideas?

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 31, 2012 @ 11:48
    Matt Brailsford
    0

    BOOM! It worked. Seems I was using the wrong key when adding the lat / lng values to the values collection. I thought because those fields weren't assigned to a tab, the key would just be the field name, but it seems it gets prefixed by an underscore, so adding that to the key and adding those values to the values collection worked. So I now have the location datatype value getting split into two database fields without the need to show the individual lat lng fields on the editor. Sweeeet! :)

    Cheers Sune / Mads for the help.

    Matt

  • Mads Krohn 211 posts 504 karma points c-trib
    Oct 31, 2012 @ 11:58
    Mads Krohn
    0

    Ohh guess I was too slow :P

  • Sune Bøegh 64 posts 374 karma points
    Oct 31, 2012 @ 12:13
    Sune Bøegh
    0

    Ah exellent! :)

    Don't hesitate to throw a comment my way, if you have suggentions or requests for features that might pop up when using it (always looking for an excuse to give DEWD some attention ;).

Please Sign in or register to post replies

Write your reply to:

Draft