Hi,
I want to disable a select in my module's mod_form.php file only if the user is modifying the instance, leaving it enabled if he's creating a new instance.
I'm having a hard time figuring this one out.
Any ideas?
If your form extends moodleform_mod, which it sounds like it does, you can check to see if the _instance property is set (see below).
/**As the comment suggests, If it is non-empty then the form is an 'add' form (new instance) rather than an update. You can then use the freeze method on the $mform (MoodleQuickForm) object or pass the disabled attribute as part of the attribute parameter to the addElement method.
* Instance of the module that is being updated. This is the id of the {prefix}{modulename}
* record. Can be used in form definition. Will be "" if this is an 'add' form and not an
* update one.
*
* @var mixed
*/
protected $_instance;
Cheers,
Sam
Worked like a charm Sam. I was trying to use the disableif but this is much simpler.
Thanks a lot!