lonnieezell / Bonfire

Jumpstart your CodeIgniter web applications with a modular, HMVC-ready, backend.
http://cibonfire.com
1.39k stars 524 forks source link

Required field option in form_dropdown #797

Open artlantis opened 11 years ago

artlantis commented 11 years ago

If I am not mistaken, bonfire has modified form_dropdown function. When I am checking the function, I saw that it takes 6 parameter. In normal way, the required option available in "label" option, therefore fourth parameter should take this option. But at the end of the function, just parsing $label paremeter as it is. Please check!

#file: helpers/MY_form_helper.php
function form_dropdown($data, $options=array(), $selected=array(), $label='', $extra='', $tooltip = '')

...

<div class="control-group {$error}">
    <label class="control-label" for="{$data['id']}">{$label}</label>
    <div class="controls">
         <select {$output} {$extra}>
            {$options_vals}
        </select>
        {$tooltip}
    </div>
</div>
artlantis commented 11 years ago

Fix

function form_dropdown($data, $options=array(), $selected=array(), $label='', $extra='', $tooltip = '', $req= false,)

...

        $required = ($req == true ? 'required' : ''); 

        $output = <<<EOL

<div class="control-group {$error}">
    <label class="control-label {$required}" for="{$data['id']}">{$label}</label>
    <div class="controls">
         <select {$output} {$extra}>
            {$options_vals}
        </select>
        {$tooltip}
    </div>
</div>

EOL;
mwhitneysdsu commented 11 years ago

The required attribute is not valid on the label element, it belongs on the select element, which means you could pass it in as part of $extra.

Additionally, if you were to add another argument to form_dropdown(), you would likely want to leave the order of the existing arguments intact, so you would add it to the end of the argument list. I'm guessing the fourth argument in CI's form_dropdown function wasn't in place when Bonfire's form_dropdown function was written, but I could be wrong.

artlantis commented 11 years ago

You are right Mat, changed the order. I did a mistake, I meant label required.