FriendsOfCake / bootstrap-ui

CakePHP: Transparently use Bootstrap
MIT License
340 stars 146 forks source link

add content at end of control #383

Closed tgoeminne closed 10 hours ago

tgoeminne commented 1 year ago

Hi,

I want to add content at the end of a form control. eg another hidden input. I can use the help option but then it will be inside the small container. Is there another option I am overlooking?

tgoeminne commented 1 year ago

hi any reply on this I am trying to figure out how this plugin works but have hard time fixing it..

$templates = [ 'inputGroupContainer' =>'<div{{attrs}}>{{prepend}}{{content}}{{append}}{{extra}}

', 'extra' => '{{content}}', ];

I am using this but with no luck all that happen is the extra

echo $this->Form->control('name', ['label' => 'Name', 'extra' => 'how are you doing?' , 'templates' => $templates]);

expected result:

how are you doing?

actual

Can tell me what I am doing wrong here?

greets, Thomas

tgoeminne commented 1 year ago

Also it would appear that the error messages are no longer shown on text inputs? Is this broken ?

ndm2 commented 1 year ago

You cannot add custom templates like that, the underlying string template functionality provided by CakePHP doesn't support that. What you can do however is adding template variables:

$this->Form->setTemplates([
    'inputContainer' =>
        '<div{{containerAttrs}} ' .
            'class="{{containerClass}}form-group {{type}}{{required}}">{{content}}{{help}}{{extra}}</div>',

    'inputContainerError' =>
        '<div{{containerAttrs}} ' .
            'class="{{containerClass}}form-group {{formGroupPosition}}{{type}}{{required}} is-invalid">' .
                '{{content}}{{error}}{{help}}{{extra}}</div>',
]);

// ...

echo $this->Form->control('name', [
    'label' => 'Name',
    'templateVars' => [
        'extra' => 'how are you doing?'
    ],
]);
tgoeminne commented 1 year ago

thanks, will take a look at that