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.
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! :)
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:
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
Victoria, I saw that you went via Angular solution what about C# ?
A team member post related to this issue.
Thanks so much! That EditorModelEventHandler class is just what I need :)
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
However the following code isn't working to set my select menu option to the sixth option (option value is 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! :)
I suggest this answer.
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
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.
is working on a reply...