CRUD Field labels and Placeholders

Hi,

I’ve been following the tutorial on Udemy and side by side also working on something of my own, I am facing two issues.
I’ve defined the model as

require 'init.php';

$label_ribbon_right = $app->add(['Message',"Add an Event",'information']);

$db = $app->dbConnect('mysql://root:root@localhost:3306/db1');

class Event extends \atk4\data\Model {
  public $table = 'c_input'; //defining the table
  function init() {
    parent::init();
    $this->addField('event_name', ['type'=>'text', 'caption'=>'Event Name', 'required'=>true]);
    $this->addField('event_reason', ['caption'=>'Reason', 'required'=>true]);
    $this->addField('event_nature', ['caption'=>'Nature', 'required'=>true]);
    $this->addField('event_date', ['type'=>'date','caption'=>'Date', 'required'=>true]);
    $this->addField('event_start_time', ['type'=>'time','caption'=>'Start Time', 'required'=>true]);
  }
}
$ques = new Event($db);
$table=$app->add('CRUD');
$table->setModel($ques);

The Modal that appears after clicking on add Events does not have the field labels, only the fields appear secondly i’m trying to add placeholders that too gives a invalid

Modal -> https://i.imgur.com/7xp5Gp3.png
Placeholder -> https://i.imgur.com/GcqGGdv.png

    $this->addField('event_name', ['type'=>'text', 'placeholder'=>'Test', 'caption'=>'Event Name', 'required'=>true]);

With some field types or situations, you have to put it inside a ‘ui’ parameter. Try this:

$this->addField('event_name', ['type'=>'text', 'ui'=>['placeholder'=>'Test'], 'caption'=>'Event Name', 'required'=>true]);
1 Like

Hi gcooka,

The placeholder worked. Any idea why the labels are not appearing?

Thanks for your response :slight_smile:

Between the lines containing “public $table” and “function init() {”, you probably need a line referencing a unique ID column (typically a Primary Key) in your database. For example:

public $table = 'c_input'; //defining the table
public $id_field = 'event_id';
function init() {