1
earplane
Disabling XoopsForm elements
  • 2006/12/9 16:18

  • earplane

  • Just popping in

  • Posts: 35

  • Since: 2002/10/1


Is there a way to disable or hide/show XoopsForm elements at runtime?

I've got a form that contains time info: Time starts with a XoopsFormDateTime element and has a duration that is set with a collection of radio buttons. But if the radio button "Custom" is chosen I'd like the user to set the duration in a new XoopsFormDateTime control that either has to become enabled or visible (if it's been hidden so far).

This is easily done with "onclick" javascript if I do things from scratch, but is it possible to do this using XoopsForms?

2
Dave_L
Re: Disabling XoopsForm elements
  • 2006/12/9 18:05

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


You can use the XoopsFormElement::setExtra method:

$xoopsOption['template_main'] = 'template filename';
require_once 
XOOPS_ROOT_PATH '/header.php';
require_once 
XOOPS_ROOT_PATH '/class/xoopsformloader.php';
...
$form = new XoopsThemeForm('form title''form1', ...);
...
$element = new XoopsFormRadio(...);
...
$element->setExtra("onClick = func;");
$form->addElement($element);
...
$xoopsTpl->assign('form_validation_js'$form->renderValidationJS());
$form->assign($xoopsTpl);
...
require_once 
XOOPS_ROOT_PATH '/footer.php';


The Javascript function "func" would go in the template.

3
earplane
Re: Disabling XoopsForm elements
  • 2006/12/9 18:51

  • earplane

  • Just popping in

  • Posts: 35

  • Since: 2002/10/1


Thanks!!! How come the only way to figure this out is to ask?

4
earplane
Re: Disabling XoopsForm elements
  • 2006/12/10 14:33

  • earplane

  • Just popping in

  • Posts: 35

  • Since: 2002/10/1


Uh, sorry, some additional questions popped up here:

I want to hide an element within a form, which means I need to know the ids of the elements... Nope! I need a way to set the id of the <-tr-> tag that contains the element that I want to hide, right? Or else I get empty rows in the form, and I don't want that. But:

1. I can't find a way to give the <-tr-> that contains the element an id. Is this possible? - or -

2. I know that the element I want to hide is inside the following <-tr->. This means that I could search for it in the DOM. Am I on the right track?

3. Would it be easier if I start using a javascript library like Prototype for stuff like this? Any recommendations?


BTW, how do I write tags in this forum without messing up the layout?

5
vaughan
Re: Disabling XoopsForm elements
  • 2006/12/10 14:49

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


why can't you use an 'IF' clause to hide the element?

if you set that up in the .php files

if(isset($element)) {
}


or even with smarty

<{if $element !== ''}>
<{/if}>

6
earplane
Re: Disabling XoopsForm elements
  • 2006/12/10 15:15

  • earplane

  • Just popping in

  • Posts: 35

  • Since: 2002/10/1


No, that would take a reload if I want to toggle show/hide (please correct me if I'm wrong). I want to do it at runtime, which means there's got to be some javascript involved (again, please correct me )

7
vaughan
Re: Disabling XoopsForm elements
  • 2006/12/10 15:40

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


yes, you're right..

for a +/- toggle to hide/view etc, yes you will need some javascript.

Login

Who's Online

167 user(s) are online (106 user(s) are browsing Support Forums)


Members: 0


Guests: 167


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits