1

default field

the error looks like this (field that I created)

I modified the code like this: ArticleRequest.php

  public function rules()
{
    return [
        'title' => 'required|min:2|max:255',
        'slug' => 'unique:articles,slug,'.\Request::get('id'),
        'content' => 'required|min:2',
        'date' => 'required|date',
        'status' => 'required',
        'category_id' => 'required',
        'description'=> 'required',
    ];
}

ArticleCrudController.php

$this->crud->addField([
                'name' => 'description',
                'label' => 'Description',
                'type' => 'text',
                'placeholder' => 'Description meta tag',
                'attributes' => [
                      'required' => true,
       ],
            ]);

Why is the style different? something is missing? thanks, you are very kind Marco

  • What do you mean by "style is different" ? – Foued MOUSSI Jan 22 '20 at 10:01
  • if you look at the first two links above, you understand thanks for the help marco –  Jan 22 '20 at 15:26
  • There are no links above, and it's unclear from the images what difference you're looking at. Tell us specifically what's wrong. Is it the "Please fill in this field" versus "The title field is required" bit? – ceejayoz Jan 22 '20 at 15:30
  • @MarcoZarpellon you should add validation rules for description like you did for title to get same appearance. See answer below – Foued MOUSSI Jan 22 '20 at 15:53
  • I would like the style to be the same as the first link: red field border and message text with a red background –  Jan 22 '20 at 16:02
  • @MarcoZarpellon I don't believe you can adjust the styling of that. It's a built-in browser message triggered by the HTML5 validation attributes like ``. – ceejayoz Jan 22 '20 at 16:07

1 Answers1

0
public function rules()
{
    return [
        'title' => 'required|min:2|max:255',
        // you should add validation rule for description attr
        'description' => 'required',
        'slug' => 'unique:articles,slug,'.\Request::get('id'),
        'content' => 'required|min:2',
        'date' => 'required|date',
        'status' => 'required',
        'category_id' => 'required',
        'description'=> 'required',
    ];
}
Foued MOUSSI
  • 4,643
  • 3
  • 19
  • 39
  • it is not very clear to me can you give me an example? 'description'=> 'required' –  Jan 22 '20 at 16:27
  • I assume you're using Laravel Backpack, If you want to get error messages with fancy styles (red alert box) for an attribute, First you must add validation rules (required, min, max ... ) to it and Backpack will do its magic for you. Check links below https://laravel.com/docs/5.8/validation#creating-form-requests https://backpackforlaravel.com/docs/3.4/crud-tutorial#the-request – Foued MOUSSI Jan 22 '20 at 16:36
  • I added validation but it doesn't work 'description'=> 'required|min:2|max:255 –  Jan 28 '20 at 07:36
  • it could be a bug? –  Jan 28 '20 at 08:36