marvinlabs / laravel-html-bootstrap-4

Bootstrap 4 fluent HTML builder
MIT License
42 stars 15 forks source link

Radio Group ID Bug #46

Closed RTC1 closed 6 years ago

RTC1 commented 6 years ago

This one seems to have appeared recently (I'm using 1.6.4):

{{ bs()->radioGroup('agree_terms_1', [
                                      'y' => 'I am interested!',
                                      'n' => 'No, thanks.',
                                    ], 'y') }}

I can't select anything other than the first radio. Upon closer inspection each radio button has the same ID:

<div class="radio-group" id="agree_terms_1_radio_group">
<div class="custom-control custom-radio">
    <input class="custom-control-input" type="radio" checked="checked" name="agree_terms_1" value="y" id="agree_terms_1">
    <label class="custom-control-label" for="agree_terms_1">I am interested!</label>
</div>

<div class="custom-control custom-radio">
    <input class="custom-control-input" type="radio" name="agree_terms_1" value="n" id="agree_terms_1">
    <label class="custom-control-label" for="agree_terms_1">No, thanks.</label>
</div>
</div>
vpratfr commented 6 years ago

Sorry about that. Forgot to run tests before releasing 1.6.4 👎

gavro commented 6 years ago

I don't think this fixes the problem, or am I the only one still getting the same id/for's in the child-form elements here? Updated to latest dev-master.

gavro commented 6 years ago

FYI: If I comment out the if ($element->control->getAttribute('id')===null) check, and always apply $element->control = $element->control->id($this->controlId($element)); it does work fine again.

vpratfr commented 6 years ago

Can you show the code you are using to produce the radiogroup?

gavro commented 6 years ago

Tested with (practically) the same code as above:

    {{ bs()->radioGroup('agree_terms', [
        'y' => 'I am interested!',
        'n' => 'No, thanks.',
    ], 'y') }}
gavro commented 6 years ago

Produced HTML (no changes):

<div class="radio-group" id="agree_terms_radio_group">
    <div class="custom-control custom-radio">
        <input class="custom-control-input" type="radio" checked="checked" name="agree_terms" id="agree_terms" value="y">
        <label class="custom-control-label" for="agree_terms">I am interested!</label>
    </div>
    <div class="custom-control custom-radio">
        <input class="custom-control-input" type="radio" name="agree_terms" id="agree_terms" value="n">
        <label class="custom-control-label" for="agree_terms">No, thanks.</label>
    </div>
</div>

Code when removing ===null check:

<div class="radio-group" id="agree_terms_radio_group">
    <div class="custom-control custom-radio">
        <input class="custom-control-input" type="radio" checked="checked" name="agree_terms" id="agree_terms_y" value="y">
        <label class="custom-control-label" for="agree_terms_y">I am interested!</label>
    </div>
    <div class="custom-control custom-radio">
        <input class="custom-control-input" type="radio" name="agree_terms" id="agree_terms_n" value="n">
        <label class="custom-control-label" for="agree_terms_n">No, thanks.</label>
    </div>
</div>
RTC1 commented 6 years ago

I can confirm the new version sorted it for me.

gavro commented 6 years ago

Ok, started with a fresh vendor folder, did a fresh composer install --prefer-dist and now it does works as stated here. Don't understand what happend here... (not a single package was "dirty" before).

Terribly sorry for the false bugreport & thanks for the fix!

vpratfr commented 6 years ago

No worries. I prefer a false positive than a negative that passes by without seeing it ;)