themosis / framework

The Themosis framework core.
https://framework.themosis.com/
GNU General Public License v2.0
671 stars 121 forks source link

Attributes key don't work in Field::text #655

Closed dimitriBouteille closed 5 years ago

dimitriBouteille commented 5 years ago

I tried to add the "attributes" property to a text field (Field::text) , but it doesn’t work in version 2.0 :(

$slides = PostType::make(...);

Metabox::make('slide', $slides->getName())
            ->setTitle('Un slide')
            ->add(Field::text('title', [
                'label' => 'Titre du slide',
                'attributes' => [
                    'id' => 'demo-id',
                    'class' => 'custom-demo',
                    'required'
                ]
            ]))
...
jlambe commented 5 years ago

Not all attributes are yet supported when used within a metabox, only on the front-end side. I'll look to bring more support of attributes on the JS components.

While there is not yet a full support of attributes, I can suggest you to define a required validation rule on the field like so:

Field::text('title', [
    'rules' => 'required'
])
jlambe commented 5 years ago

The 2.0 branch now contains an update with support of attributes to most of the fields components. Custom class names are supported as well as data- attributes and other. But as this is now ReactJs controlled components, not sure all attributes are relevant. It's there now, coming on the 2.0.2 release.