open-admin-org / open-admin

open-admin forked from z-song/laravel-ladmin. Removing jquery, now based on Bootstrap5, vanilla JS
https://open-admin.org
MIT License
259 stars 75 forks source link

How to create a dynamic input field style in form? #178

Closed vincentchoo-intern closed 5 months ago

vincentchoo-intern commented 5 months ago

I wanted to make a form dynamic by having a red border if the status of a model is false.


protected function form($model = null, $status = null)
{

    $true = $model->status !== 0;
    $form->textarea('feedback', __('Feedback'))->disabled(false)->placeholder('')->attribute($true ? '' : ['style' => 'border: 1px solid red;']);

}

I code the line like this and it works. The red border shows up. ,but the submit buttons stops working. Somehow submit buttons doesn't work when I reference the model? Is there a reason or solution to this?

Edit: I found out that I can't use $form->model to check the data because the model remains null up until saving, so I tried to add a parameter in the form method to retrieve the intended model.

vincentchoo-intern commented 5 months ago

Okay I found out that if I write the code from this

$true = $model->status !== 0;

to this

$true = $model ? $model->status !==0 : '' ;

it works.