Coder Social home page Coder Social logo

minphp-form's Issues

Select options cannot be defined between optgroups

When using Form::select and including options that are set as <optgroup> tags, the optgroup is only closed when the end of the options have been reached or a new optgroup has been started. Thus, there is no way to set an <option> outside of an <optgroup> if an <optgroup> has already been created earlier in the option list.

There should be an option to close an optgroup just like there is an option to create an optgroup, i.e., specifying the value "close_optgroup" to close any open optgroup similar to how the value optgroup closes and begins a new optgroup.

For example, setting the following options:

$options = array(
    array('name' => "Group 1", 'value' => "optgroup"),
    array('name' => "Item 1", 'value' => "1"),
    array('name' => "Item 2", 'value' => "2"),
    array('name' => "", 'value' => "close_optgroup"),
    array('name' => "Item 3", 'value' => "3"),
    array('name' => "Group 2", 'value' => "optgroup"),
    array('name' => "Item 4", 'value' => "4"),
    array('name' => "Group 3", 'value' => "optgroup"),
    array('name' => "Item 5", 'value' => "5"),
);

...should render the following HTML select options where "Item 3" is outside of an optgroup:

<select name="x">
    <optgroup label="Group 1">
        <option value="1">Item 1</option>
        <option value="2">Item 2</option>
    </optgroup>
    <option value="3">Item 3</option>
    <optgroup label="Group 2">
        <option value="4">Item 4</option>
    </optgroup>
    <optgroup label="Group 3">
        <option value="5">Item 5</option>
    </optgroup>
</select>

Select option values are doubly-html-encoded

When using a Select/MultiSelect form field, the option values are doubly-html-encoded, which results in inaccurate values when any characters are converted, like ">" being converted to "&gt;". This appears to be caused by the use of Html::safe() via Html::_() which is set when the select option value is set in Form::selectOptions() (line 662) and again when used via Html::buildAttributes() shortly thereafter (line 670).

The solution looks to be in changing line 662:
$attr['value'] = $this->_($value, true);
to
$attr['value'] = $value;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.