Ticket #393 (new enhancement)

Opened 4 years ago

Last modified 3 years ago

Make Meta Controls action aware

Reported by: VexedPanda Owned by: somebody
Priority: minor Milestone: 1.1.3
Component: QForms Version: 1.0.0 Stable
Keywords: Cc:

Description

I often find that I want some child control of a metacontrol to depend on the value of another. Think country-state dropdowns.
Right now, I have to code this functionality into every form that uses them.

Ideally, I should be able to handle the change event from within the metacontrol itself. But QAjaxControlAction requires a QControl to fire the event on.

So I suggest we either change MetaControls? to extend QControl, or remove the QControl restriction on action callbacks (probably the later).

Change History

Changed 4 years ago by VexedPanda

  • component changed from Other to QForms

Changed 4 years ago by VexedPanda

Ok, so the reason it needs a QControl for this is that the QForm needs a reference to the object that it can look up based on control name (since that's all that the PostAjax? javascript supplies). I'm not sure there's an elegant way around this limitation.

So what we'd need to do is a) Make the Meta Control extend QControl, and b) During contstruct, add the meta control to the form as a control (so it becomes part of the form's objControlArray where it can find it).

Changed 4 years ago by VexedPanda

We'd also have to declare QControlBase::ParsePostData?, QControlBase::GetControlHtml?, and QControlBase::Validate. They don't need to do anything.

And we'd have to set a unique control Id using $this->objForm->GenerateControlId?().

Changed 4 years ago by VexedPanda

Ok, the unique id and adding to the form can both be covered simply by:

parent::__construct($objParentObject);

Duh me.

Changed 4 years ago by VexedPanda

Ok. I've tested this myself by making the following changes:
In the *MetaControlGen? class change:

extends QBaseClass {

to:

extends QControl {
	public function ParsePostData() {}
	public function GetControlHtml() {}
	public function Validate() {}

Add:

parent::__construct($objParentObject);

after

$this->objParentObject = $objParentObject;

Then, in the non-gen class, you can do things like

$someControl->AddAction(new QChangeEvent(), new QServerControlAction($this, 'someControl_Change'));

I'll try and roll a patch soon, but I'm pretty busy lately. :(

Changed 3 years ago by alex94040

Vexed - I understand exactly what you're trying to do, and it makes perfect sense.

So, the key here is that the QForm needs to be able to find the "control" by name. So far, the only "named" things that the QForm has are QControls. The problem is, just like you said, if we make MetaControls? extend QControl, you get empty Parse/GetControlHtml? methods. You also get a bunch of inherited properties from QControl that you don't want. And that's kinda ugly.

Idea: how about we introduce an abstract class to the hierarchy, called "NamedItem?"? Where QControl would extend from NamedItem?, and MetaConrol? would extend from NamedItem?? Then, the only thing that a named item would do is, ahem, have a name. All Parse/GetControlHtml? things would remain with QControls, and MetaControls? won't have to have them. The Ajax/ServerControlAction? would accept a NamedItem?, not a QControl.

What do you think?

Changed 3 years ago by VexedPanda

Hmm, that sounds like a pretty good idea. Hopefully it won't take much to convert the QForm's lookup via objControlArray to use the named item array instead.

Changed 3 years ago by alex94040

  • milestone changed from 1.1.1 to 1.1.2

Changed 3 years ago by alex94040

  • milestone changed from 1.1.2 to 1.1.3
Note: See TracTickets for help on using tickets.