Commit 28a72736 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Make pieform fieldsets remember whether they're open or closed



When a user toggles a collapsible fieldset open or closed, it's handy
if they don't have to keep changing it back every time they submit the
form.  This is useful in an 'advanced options' section of a search
form, for example.

Change-Id: Idb93dc1c0ba8d8f8b63b2ed0bff69e5a043b0247
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent afadb872
......@@ -51,6 +51,9 @@ function pieform_element_fieldset(Pieform $form, $element) {/*{{{*/
if (!isset($_PIEFORM_FIELDSETS['forms'][$formname])) {
$_PIEFORM_FIELDSETS['forms'][$formname] = array('formname' => $formname);
}
if (isset($element['name'])) {
$openparam = $formname . '_' . $element['name'] . '_open';
}
// Work out whether any of the children have errors on them
$error = false;
foreach ($element['elements'] as $subelement) {
......@@ -60,7 +63,8 @@ function pieform_element_fieldset(Pieform $form, $element) {/*{{{*/
}
}
if (!empty($element['collapsed']) && !$error
&& (!isset($element['name']) || param_alphanumext('fs', null) != $element['name'])) {
&& (!isset($element['name'])
|| (param_alphanumext('fs', null) != $element['name'] && !param_boolean($openparam, false)))) {
$classes[] = 'collapsed';
}
}
......@@ -70,6 +74,10 @@ function pieform_element_fieldset(Pieform $form, $element) {/*{{{*/
$result .= '<legend>';
if (!empty($element['collapsible'])) {
$result .= '<a href="">' . Pieform::hsc($element['legend']) . '</a>';
if (isset($openparam)) {
$result .= '<input type="hidden" name="' . hsc($openparam) . '" class="open-fieldset-input" '
. 'value="' . intval(!in_array('collapsed', $classes)) . '">';
}
}
else {
$result .= Pieform::hsc($element['legend']);
......@@ -113,6 +121,10 @@ function pieform_update_legends(element) {
if (legend.firstChild.tagName == 'A') {
connect(legend.firstChild, 'onclick', function(e) {
toggleElementClass('collapsed', fieldset);
var input = getFirstElementByTagAndClassName('input', 'open-fieldset-input', legend);
if (input) {
input.value = !hasElementClass(fieldset, 'collapsed');
}
e.stop();
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment