Skip to content

Bug: View Cell Inheritance Issue in Placeholder Values #8326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hamransp opened this issue Dec 13, 2023 · 2 comments · Fixed by #8330
Closed

Bug: View Cell Inheritance Issue in Placeholder Values #8326

hamransp opened this issue Dec 13, 2023 · 2 comments · Fixed by #8330
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@hamransp
Copy link

PHP Version

8.1

CodeIgniter4 Version

v4.4.3

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

mysql 5.6

What happened?

When employing the view_cell function in CodeIgniter 4 with the provided InputCell class, a bug is observed where the test2 cell erroneously inherits the placeholder value from the preceding test1 cell, even when no explicit placeholder value is provided for test2.

Steps to Reproduce

Implement an InputCell class using the provided code.
Utilize the view_cell function in a view file (profil.php) to render two cells, namely test1 and test2.
Omit providing a placeholder value for test2.

app\Cells\InputCell.php

<?php
namespace App\Cells;
use CodeIgniter\View\Cells\Cell;
class InputCell extends Cell
{

    public $type;
    public $name;
    public $id;
    public $label;
    public $placeholder;
     public $required = false;
}

app\Cells\input.php

<div>
    <label for="<?= esc($id ?? null) ?>" class="relative block py-1 border border-gray-200 rounded-md shadow-sm focus-within:border-sky-50 focus-within:ring-1 focus-within:ring-blue-600">
        <input type="<?= esc($type ?? null) ?>" name="<?= esc($name ?? null)  ?>" id="<?= esc($id ?? null) ?>" class="w-full py-2 bg-transparent border-none placeholder-slate-300 placeholder:text-md peer focus:border-transparent focus:outline-none focus:ring-0" placeholder="<?= esc($placeholder ?? '') ?>" <?= esc($required ?? false) ?>>
        <span class=" pointer-events-none absolute start-2.5 top-0 -translate-y-1/2 bg-white p-0.5 text-xs text-gray-700 peer-focus:top-0">
            <?= esc($label ?? null) ?>
        </span>
    </label>
</div>

app\Views\dashboard\biodata\profil.php

  <div id="test1">
            <?= view_cell('InputCell', ['type' => 'text', 'label' => 'test1 label', 'name' => 'test1', 'placeholder' => 'XXX']); ?>
        </div>
        <div id="test2">
            <?= view_cell('InputCell', ['type' => 'text', 'label' => 'test2 label', 'name' => 'test2'); ?>
        </div>

Screenshot_1ci

Expected Output

The test2 cell should display with an empty placeholder or the default placeholder value specified in the InputCell class.

Anything else?

No response

@hamransp hamransp added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 13, 2023
@michalsn
Copy link
Member

Please use a class name with namespace: App\Cells\InputCell or InputCell::class - otherwise we will use Factories under the hood which will always return a shared object for the same class name.

@michalsn
Copy link
Member

Thanks @hamransp - it's now fixed. From the next release, there will be no need to use the full namespace to get the new instance of a cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
2 participants