Copied to clipboard

Flag this post as spam?

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


  • Victoria 14 posts 114 karma points
    May 20, 2019 @ 03:42
    Victoria
    0

    Default radio button option not saving in piece of Umbraco content

    Hi there,

    I have a content type I've set up, and part of it includes radio buttons in which a user needs to select the store type (I used the radio buttons data type in Umbraco for this).

    There was no way to select a default 'checked' option in the data type, so I'm programmatically selecting the second option as the default to be checked when the page loads:

    if (!angular.element('input[name=radiobuttons-storeType]').prop('checked')) {
        var checkboxes = angular.element('input[name=radiobuttons-storeType]');
        if (checkboxes[1]) {
            var $checkbox = $(checkboxes[1]);
            $checkbox.prop("checked", true);
        }
    }
    

    However I'm finding if I don't interact with the radio buttons, the default value isn't getting saved when I save the form (it's giving me an error saying the value can't be empty, however the button is checked when you look at the interface).

    Just wondering what I need to do to get Umbraco to save the default value if the radio buttons aren't being interacted with/manually checked.

    The code to set the default option is contained in a controller for another custom data type I have set up, since this one didn't have it's own controller. I'm wondering if this might be the issue - perhaps it needs it's own controller to work as I'm hoping.

    Many thanks in advance for your help.

    Cheers,

    Victoria

  • Tarik | WPPlumber 179 posts 801 karma points c-trib
    May 24, 2019 @ 18:48
    Tarik | WPPlumber
    100

    Victoria, I saw that you went via Angular solution what about C# ?

    A team member post related to this issue.

  • Victoria 14 posts 114 karma points
    May 27, 2019 @ 02:36
    Victoria
    0

    Thanks so much! That EditorModelEventHandler class is just what I need :)

  • Victoria 14 posts 114 karma points
    May 27, 2019 @ 02:46
    Victoria
    0

    That's working perfectly with my radio buttons, but when I try using the same logic with a drop down menu I have, it's not holding the values for some reason.

    This is the code that's working for my radio buttons

    SetDefaultValue(e, new string[] { "storeLocation" }, "storeType", "1111");
    

    However the following code isn't working to set my select menu option to the sixth option (option value is 5):

    SetDefaultValue(e, new string[] { "storeLocation" }, "state", "5");
    

    The doc type alias and property alias are definitely correct, so not sure why this wouldn't be working. Any input would be greatly appreciated! :)

  • Tarik | WPPlumber 179 posts 801 karma points c-trib
    May 27, 2019 @ 14:26
    Tarik | WPPlumber
    0

    I suggest this answer.

  • Victoria 14 posts 114 karma points
    May 29, 2019 @ 02:25
    Victoria
    0

    Hi Tarik!

    Thanks again - that's incredibly helpful!

    Is there any way I can target the drop down I'm using in my specific document type rather than all of the drop downs on the site?

    Cheers,

    Victoria

  • Tarik | WPPlumber 179 posts 801 karma points c-trib
    May 29, 2019 @ 06:39
    Tarik | WPPlumber
    0

    Victoria, peace be upon those who follow guidance.

    I suggest to create a custom data type for your target and use it in that document type only.

Please Sign in or register to post replies

Write your reply to:

Draft