From: Christian Weiske on
Hi all,


When adding multiple rules to an qf2 element, using the fluent
interface does not work anymore - every addRule() call returns the
created rule and not the element.
I do see that this is needed for further rule modifications or using
them in and/or chains, it makes the simple cases more complicated.

What about a copy of addRule() that returns the qf element?
Instead of
> $el = $form->addElement(..);
> $el->addRule(...);
> $el->addRule(...);
> $el->addRule(...);
one could use
> $form->addElement(..)
> ->addRuleE(...)
> ->addRuleE(...)
> ->addRuleE(...)

What do you think about that?

--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-
From: Alexey Borzov on
Hi Christian,

On 04.05.2010 20:55, Christian Weiske wrote:
> When adding multiple rules to an qf2 element, using the fluent
> interface does not work anymore - every addRule() call returns the
> created rule and not the element.
> I do see that this is needed for further rule modifications or using
> them in and/or chains, it makes the simple cases more complicated.
>
> What about a copy of addRule() that returns the qf element?
> Instead of
>> $el = $form->addElement(..);
>> $el->addRule(...);
>> $el->addRule(...);
>> $el->addRule(...);
> one could use
>> $form->addElement(..)
>> ->addRuleE(...)
>> ->addRuleE(...)
>> ->addRuleE(...)
>
> What do you think about that?

1) Please note that addElement() you are using in your example returns the added
element rather than the form. Do we need addElementF() also?
2) What exactly are you trying to achieve here? Saving a few keystrokes by not
having to type $el a couple of times?
From: Christian Weiske on
Hi Alexey,


> > When adding multiple rules to an qf2 element, using the fluent
> > interface does not work anymore - every addRule() call returns the
> > created rule and not the element.
> > I do see that this is needed for further rule modifications or using
> > them in and/or chains, it makes the simple cases more complicated.
> >
> > What about a copy of addRule() that returns the qf element?
> 1) Please note that addElement() you are using in your example
> returns the added element rather than the form. Do we need
> addElementF() also?
That depends - if there are many things to do with a form object, maybe
yes.

> 2) What exactly are you trying to achieve here?
> Saving a few keystrokes by not having to type $el a couple of times?
Yep, I would like to
a) not assign a variable at all
b) save keystrokes, get cleaner code - and more consistent code, since
the fluent interface is partly provided already. Currently the fluent
interface cannot be through the *whole* element setup process and feels
half-baken.


--
Regards/Mit freundlichen Grüßen
Christian Weiske

-= Geeking around in the name of science since 1982 =-
From: Ken Guest on
On Wed, May 5, 2010 at 4:16 PM, Christian Weiske <cweiske(a)cweiske.de> wrote:
> Hi Alexey,
<snip>
>> 2) What exactly are you trying to achieve here?
>> Saving a few keystrokes by not having to type $el a couple of times?
> Yep, I would like to
> a) not assign a variable at all
> b) save keystrokes, get cleaner code - and more consistent code, since
> the fluent interface is partly provided already. Currently the fluent
> interface cannot be through the *whole* element setup process and feels
> half-baken.


Would it be fair to say it is truly geborked?


K.


--
http://blogs.linux.ie/kenguest/
From: Christian Weiske on
Hi Alexey,




> > > When adding multiple rules to an qf2 element, using the fluent
> > > interface does not work anymore - every addRule() call returns the
> > > created rule and not the element.
> > > I do see that this is needed for further rule modifications or
> > > using them in and/or chains, it makes the simple cases more
> > > complicated.
> > >
> > > What about a copy of addRule() that returns the qf element?
> > 1) Please note that addElement() you are using in your example
> > returns the added element rather than the form. Do we need
> > addElementF() also?
> That depends - if there are many things to do with a form object,
> maybe yes.
>
> > 2) What exactly are you trying to achieve here?
> > Saving a few keystrokes by not having to type $el a couple of times?
> Yep, I would like to
> a) not assign a variable at all
> b) save keystrokes, get cleaner code - and more consistent code, since
> the fluent interface is partly provided already. Currently the fluent
> interface cannot be through the *whole* element setup process and
> feels half-baken.

Better idea: Add addRule() to Rule.php itself:

public function addRule($rule, $message = '', $options = null)
{
return $this->owner->addRule($rule, $message, $options);
}

This would be consistent in the way that Rule.php already has _or() and
_and() - plus the fluent interface would work fine.

--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-