Skip to content
This repository

CFormElement.getVisible() caching and tabular input #613

Open
MonkeyMaster opened this Issue · 4 comments

2 participants

MonkeyMaster Carsten Brandt
MonkeyMaster

CFormElement.getVisible() always caches the result of evaluateVisible(). When using CForm for tabular input getVisible() is evaluated for the first model only and is possibly incorrect for the others - depending on scenario and other factors.

Is it possible to make CFormElement.getVisible() similar to CFormInputElement.getRequired() - no caching?

This is how it's done now:

<?php
public function getVisible()
{
    if($this->_visible===null)
        $this->_visible=$this->evaluateVisible();
    return $this->_visible;
}

public function getRequired()
{
    if($this->_required!==null)
        return $this->_required;
    else
        return $this->getParent()->getModel()->isAttributeRequired($this->name);
}
Carsten Brandt
Collaborator
cebe commented

As it is cached inside the object, there should not be a problem. Are you using the same object for displaying different rows and if yes, why?

MonkeyMaster

Why wouldn't I re-use the form for different rows if they represent the same model class (HAS_MANY relation)? It saves some resources and time, isn't it?..

I already overloaded CFormInputElement to remove visibility caching and to add support for tabular input names (ex. '[1]name'). Both things are easy to implement.

It would be great to have this functionality out of the box since CHtml and CActiveForm support tabular input

Carsten Brandt
Collaborator
cebe commented

Hm... not sure whats the problem here, can you give the code of your view?

MonkeyMaster

It doesn't help since my view is just $form->render(). Since CForm still doesn't support tabular input I made a widget for that compatible with CForm config (like sub-form) and acting much like it (cycling through models though).

The problem: CFormInputElement doesn't recognize tabular input names with [] and caches attribute's visibility which prevents re-using the same element for different rows. Moreover there's no way to clear that cache without loosing the value that was set via form config.

If you ever plan to add tabular input support to CForm all this gets in the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.