Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:lib/formslib.php Form Definition: Difference between revisions

From MoodleDocs
No edit summary
Line 48: Line 48:
How this can be done?
How this can be done?
Thanks.
Thanks.
==Dependent Dropdown Lists==
Does Formslib support adding dependent dropdown lists to a form? This is where the options that are displayed on list2 are dependent on the option that is selected on list1.
The [https://moodle.org/mod/forum/discuss.php?d=163019 how to implement dependent dropdown lists] discussion on the Using Moodle forum talks about something similar and offers a "hacky" approach. But that was in 2010. Can this be easily done in Moodle 2.5/2.6?

Revision as of 12:39, 7 February 2014

There's items on here (e.g. 'duration') that are 2.0 only. Please can people adding them mark them as such to avoid confusion. Ta --Howard Miller 11:42, 23 July 2009 (UTC)

Hi Howard, You can just add {{Moodle 2.0}} to those items. I did that for 'duration'. --Frank Ralf 11:54, 23 July 2009 (UTC)

No default value attribute for editor??

tried the context key but doesn't work.

Use Static elements with care?

Why are static elements listed as being used with care?

Please do not create conditional elements in definition(), the definition() should not directly depend on the submitted data.

I'm really not sure what this means. Does it actually mean "do not create elements that are conditional upon the values of other submitted elements" as opposed to not creating conditional elements at all? Lots of forms have conditional elements --Howard Miller 13:06, 6 February 2011 (UTC)

Yes, it means don't create things that are conditional on the data that the form will be editing. It is OK to condition on admin settings (e.g. if conditional activities are turned off, those options do not appear on the mod_edit forms. Or, perhaps, on capabilities. However, in that case you have to be careful. If someone without the capability uses the form, you have to make sure that when they submit, you don't overwrite the correct value in the database with blank from the form. In that situation, it may be better to use hardFreeze on those form elements, instead of conditionally omitting them.--Tim Hunt 15:14, 6 February 2011 (UTC)

Very disappointing, that nested fieldsets are not supported :(

"$mform->addElement('header', 'nameforyourheaderelement', get_string('titleforlegened', 'modulename')); You can't yet nest these visible fieldsets unfortunately. But in fact groups of elements are wrapped in invisible fieldsets. You close a fieldset with moodle_form's closeHeaderBefore method. You tell closeHeaderBefore the element before you wish to end the fieldset. A fieldset is automatically closed if you open a new one."


Should be possible to nest fieldsets! Please add this feature!


As I know this feature was already added to QuickForms.
See example QuickForm solution of nested fieldset here:
http://pear.saltybeagle.com/HTML_QuickForm_Renderer_Tableless/stack.php
Konrad Lorinczi - - 18:02, 23 March 2011 (UTC)

Multiple file uploads?

If one has multiple files to be uploaded using the form and all files are to go in different location. It feels like, the below code does not satisfy the needs to do anything of this sort.


after form submission and validation use

if ($data = $mform->get_data()) {

     ...
   $mform->save_files($destination_directory);
     ...

}


How this can be done? Thanks.

Dependent Dropdown Lists

Does Formslib support adding dependent dropdown lists to a form? This is where the options that are displayed on list2 are dependent on the option that is selected on list1. The how to implement dependent dropdown lists discussion on the Using Moodle forum talks about something similar and offers a "hacky" approach. But that was in 2010. Can this be easily done in Moodle 2.5/2.6?