I have it so that the user can set the theme using the “Toggle Theme” option which is found under their avatar. I found somewhere this code which showed how to override the switch_theme
function with the following:
hooks.py
override_whitelisted_methods = {
"frappe.core.doctype.user.user.switch_theme": "tweaks.overrides.theme.switch_theme"
}
And then this code:
import frappe
@frappe.whitelist()
def switch_theme( theme ):
if theme in [ "Dark", "Light", "Automatic", "Apricot", "Midnight Blue", "Newara" ]:
frappe.db.set_value( "User", frappe.session.user, "desk_theme", theme )
So when the user clicks on their avatar and selects “Toggle Theme”, they get this popup and they can switch their theme.
But the problem lies in the User Document Form. Using JavaScript, I can successfully add the options to the Desk Theme drop down:
frappe.ui.form.on( "User", "refresh", function( frm ){
frm.set_df_property( "desk_theme", "options", [ "Dark", "Light", "Automatic", "Apricot", "Midnight Blue", "Newara" ] );
frm.refresh_field( "desk_theme" );
} );
But the minute I try to save the user document, I get the following:
I can’t save the user as long as they have a theme selected that is not one of the three. Granted I can just switch their theme to one of the three in order to successfully save, but that messes with them and frankly shouldn’t be necessary.
Does anyone have any ideas on how I continue with the custom themes but allow selection of them in the user document form?