Forums | Mahara Community
Developers
/
Custom Pieform Template
05 December 2011, 2:47
Hello Everyone,
Regarding the pieform custom templates (php templates) what are the required js files or php files in order to make the wygiwys and calendar to work. we manged to display the forms the way we want but still we didn't mange to include the javascript files required to do the run them perfectly.
Any help is appreciated
Best,
Mohammad
05 December 2011, 7:58
Hello again,
I forgot to ask about another matter, if you go to mahara/admin/site/options.php, you see multiple fieldsets, each one is collapsed or expanded when you click on its title (legend); I was hopping if can guide me to the JavaScript function does that.
Thanks in advanced.
Best
Mohammad
05 December 2011, 14:56
Hi Mohammad, it should just happen automatically when you set the 'collapsible' property on the fieldset element of the pieform - I think the javascript is created inline when the pieform html is built.
06 December 2011, 6:04
Thanks for replying Richard
What you say is correct, but when you use custome template (see mahara/theme/raw/pieforms/adduser.php for example) you'll have to rebuild the fieldset from the scratch, my problem was to find the onclick event handler to collapse/expand the fieldset.
I have solved the problem anyway using a jquery; I add/remove the a class called "collapsed" on the click event as follows:
<fieldset class=”pieform-fieldset collapsible collapsed”><legend onclick="toggle(this.parentNode)"> .... <script> function toggle(element) { $(element).toggleClass('collapsed'); } </script>
Best
Mohammad
05 December 2011, 15:11
The wysiwyg and calendar js should be included automatically when you add those elements into a pieform. The way it's done is that every pieform element adds its own html into the page's head element by implementing the pieform_element_<element>_get_headdata() function.
When the pieform constructor is called, all this 'headdata' is stored in global variables which is then put on the page by the smarty() function.
The trouble with this method is that on every page you need to remember to call pieform() *before* you call smarty(), otherwise the headdata javascript won't get into the page. So something like this will work:
$form = pieform($formdef);
$smarty = smarty();
$smarty->assign('form', $form);
But the following won't work:
$smarty = smarty();
$smarty->assign('form', pieform($formdef));
I've been meaning to add a patch to spit out a warning whenever pieform() is called second, it might save developers a few headaches.