Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Select option only works with Fastform #190

@ruifcastro

Description

@ruifcastro

Hi, I need some help, I can't get the select option to work.

I can only get "selects" to work with fastform

$opcoes = [
	'4' => '4 Horas',
	'24' => '1 Dia',
	'48' => '2 Dias',
	'72' => '3 Dias',
];

$data = [
	'select' => [ 
		'name'     => 'duracao', 
		'label'    => 'Duração: ', 
		'options'  => $opcoes, 
		'selected' => '4' 
	]
];
$form->fastform($data);

Initially I had this:

$options = [
	'4'	=> '4 Horas',
	'24' 	=> '1 Dia',
	'48' 	=> '2 Dias',
	'72' 	=> '3 Dias',
];
$form->select('duracao','Duração: ','','','','','4',$options);

I noticed in the method protected function _create_select($data) at the very end, this part doesn't work:

if (! empty($data['label'])) {
    # output the element and label without a wrapper
    $element .= $this->label($data).PHP_EOL;
    $element .= $return.PHP_EOL;
    return $element;
} else {

If I remove it and just run this it works:

$element .= $return.PHP_EOL;
return $this->_wrapper($element, $data);

Is this a bug or something I am missing? Do I have to set a wrapper? And why without a wrapper it doesn't work?

This is the section of code I'm talking about:

if (empty($data['fastform'])) {
    if (! $this->wrapper) {
        if ($this->comments) {
            $element .= PHP_EOL.'<!-- '.$data['name'].' -->'.PHP_EOL;
        }
        if (! empty($data['label'])) {
            # output the element and label without a wrapper
            $element .= $this->label($data).PHP_EOL;
            $element .= $return.PHP_EOL;
            return $element;
        } else {
            # just return the element
            $element .= $return.PHP_EOL;
            return $this->_wrapper($element, $data);
        }
    } else {
        # wrap the element
        $element .= $return;
        return $this->_wrapper($element, $data);
    }
}

If I change it like this I get two labels:

if (empty($data['fastform'])) {
    if (!$this->wrapper) {
        if ($this->comments) {
            $element .= PHP_EOL.'<!-- '.$data['name'].' -->'.PHP_EOL;
        }
        if (! empty($data['label'])) {
            # output the element and label without a wrapper
            $element .= $this->label($data).PHP_EOL;
        }

        # just return the element
        $element .= $return.PHP_EOL;
        return $this->_wrapper($element, $data);
    } else {
        # wrap the element
        $element .= $return;
        return $this->_wrapper($element, $data);
    }
}

If I remove the label it seems to work but now I have two similar code parts but one has a PHP_EOL. Can you check what is happening here?

if (empty($data['fastform'])) {
    if (!$this->wrapper) {
        if ($this->comments) {
            $element .= PHP_EOL.'<!-- '.$data['name'].' -->'.PHP_EOL;
        }

        # just return the element
        $element .= $return.PHP_EOL;
        return $this->_wrapper($element, $data);
    } else {
        # wrap the element
        $element .= $return;
        return $this->_wrapper($element, $data);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions