Default value of select editable (Issue #40) #41

Open
wants to merge 1 commit into
from

1 participant

@honza889

I founded bug in Grid::render, in this part:

    if($input instanceof \Nette\Forms\Controls\SelectBox){
        $items = $this['gridForm'][$this->name]['rowForm'][$name]->getItems();
        // $items is array( "high"=21, "low"=15, "none"=0 )
        // $row[$name] is "low"
        if(in_array($row[$name], $items)){ // returns true
            // replace "low" with "none"
            $row[$name] = array_search($row[$name], $items);
        }
        // $row[$name] is now "none"
    }

https://github.com/Niftyx/NiftyGrid/blob/master/libs/NiftyGrid/Grid.php#L936

I suggest replace in_array() with !array_key_exists():

        if(!array_key_exists($row[$name], $items)){

It should resolve it to the satisfaction of all - if value in table exist as a key,
is used this option, only if doesnt exist as a key, is used option with this as a value.

@honza889 honza889 Default value of select editable (Issue #40)
in_array() returns true, when $needle is in array as value, but also when it is in array as key
holubj/NiftyGrid#40
57a7fdd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment