General developer forum

 
 
Picture of Joshua Johnston
How can I make an admin_setting_* field require a value?
 

HI,

I have a few admin settings that require an admin to enter a value. Is there a flag on the admin_setting subclasses that would make sure the field is not empty? I would hate to have to subclass each type just to enforce this requirement.

 
Average of ratings: -
Picture of Darko Miletić
Re: How can I make an admin_setting_* field require a value?
Group DevelopersGroup Particularly helpful Moodlers

You have to subclass each type. Settings library is major PITA. Begs for a rewrite.

 
Average of ratings: -
Picture of Darko Miletić
Re: How can I make an admin_setting_* field require a value?
Group DevelopersGroup Particularly helpful Moodlers

Be also careful with that check and make sure it does not prevent module from being installed. During module installation Moodle will detect and offer settings for a user to set of a new module. If there are no defaults and user does not enter anything Moodle will not stop showing them until some resonable value is entered by the user. This also screws CLI installations/upgrades.

 
Average of ratings:Useful (1)
Picture of Joshua Johnston
Re: How can I make an admin_setting_* field require a value?
 

Thanks for the insight. It looks like I'd be better off making a custom settings page and having an 'enable' checkbox that controls the settings that I want to make required.

 

Backstory: A plugin I am writing requires you to enter the URL of the remote server that it is using for an activity module and without the URL the plugin cannot function.

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: How can I make an admin_setting_* field require a value?
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

I think a more feasible option is to just have your plugin display a polite error message if it is not set up properly.

Think about this scenario: an admin installs your plugin into their Moodle, but does not currently know where the other server will be. They have to be able to click 'Save changes' on the 'Update settings' page to complete the install, so the only viable option is for them to leave that setting blank for now, and fill it in later.

 
Average of ratings: -