twitter-bootstraplaminaslaminas-dependency-plugin

Reset row_class or assign a different value instead of adding a new one


I'm using the twbs-helper-plugin in a Laminas project to render form elements.

I can't figure out how to define form elements without a spacing between them. By default, class="mb-3" is added to all divs containing an input element. Setting 'row_class' => 'mb-0' won't have any effect, because it will be added to the row classes resulting in class="mb-3 mb-0".

This is the definition I used:

$this->add([
    'name' => 'username',
    'options' => [
        'row_class' => 'mb-0', 
    ],
    'attributes' => [
        'placeholder' => 'Username',
        'class' => 'input-lg',
    ],
     'required' => true,
]);

Is there a way to reset the default row_class and set it to another value?


Solution

  • The default spacing class can be deactivated by using 'row_spacing_class' => false in the options:

    $this->add([
        'name' => 'username',
        'options' => [
            'row_spacing_class' => false, 
        ],
        'attributes' => [
            'placeholder' => 'Username',
            'class' => 'input-lg',
        ],
         'required' => true,
    ]);
    

    This will result in the wrapping element of the input having no bottom margin. For a custom margin, you can add 'row_class' => 'mb-*' to the options or override the value of $defaultRowSpacingClass from the twbshelper module in the application configuration.