Re: how to avoid having class attribute overwritten ?

From: Date: Thu, 12 Jul 2007 07:30:56 +0000
Subject: Re: how to avoid having class attribute overwritten ?
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47428@lists.php.net to get a copy of this message
unless you have explicity loaded the elements array prior to assigning values by using $this->elements = $flexy->getElements(); The code below will not work. - flexy merges the template elements and the elements array at ouput() stage. Regards Alan Gael Canal wrote:
hmmm sorry. Here is a detailed explanation. I have added some color for the sake of clarity. here is what I mean : depending on DB metadata, I want to set a class to an element. // class "required" if (preg_match('/not_null/',$field['flags'])) {
     if ($this->elements[$field['name']]) {
        $this->elements[$field['name']]->attributes['class'] .= ' required';
     }
} in the template, however, the field already has other(s) class(es) applied to it : <input name="foo_id" id="foo_id" type="text" class="input-text whatever" /> with the above, compiled code looks like :
                    <div>
                        <label class="labelgauche">required field sample</label>
                        <?php echo $this->elements['foo_id']->toHtml();?>
                    </div>
(... which is not very helpful, but mentionned if needed ) the generated HTML, is something like : <div> <label class="labelgauche">required field sample</label> <select name="foo_id" id="foo_id" tabindex="" class=" required"><option value="1">val 1</option><option value="2">val 2</option></select> </div> See how the "input-text whatever" classes disapeared in the wild ? What I would like to see ultimately is class="input-text whatever required" So my concern is to be able to programatically add a class to my element, without removing those already statically defined (this being even more important, considering that the templates+HTML design are handled by another person). I tried the class affectation with different methods (setAttributes, direct affectation (=), concatenation (.=)), but always with the same result Any hint would be greatly appreciated. Best regards, Gael Le jeudi 12 juillet 2007 à 10:50 +0800, Alan Knowles a écrit :
Gael Canal wrote:
Hello Alan, I have a slight problem with flexy : when I programatically set a class attribute to an element, the classes already defined in the template are ignored. (eg : i want to automatically add "required", when simultaneously my template designer uses an "edit-text" class for the given element => the generated code removes the "edit-text" leaving only the "required" class) I tried bot wiht setAttributes, attributes[]= and attributes[].= with same results. Any hint ?
Looks like it could do with a example of what you've got, what you want, and what happens etc. BTW, did you want to cc pear-dev@lists.php.net <mailto:pear-dev@lists.php.net> - This information may be useful to others. Regards Alan
Regards, and again, thanks for you very kind and patient help. Gael
    


« previous php.pear.dev (#47428) next »