GithubHelp home page GithubHelp logo

Comments (7)

cotiga avatar cotiga commented on July 18, 2024 1

If that helps, because I have been looking for a while before finding

{{ Form::radio('name', 'M.', true, ['class' => 'form-check-input', 'id' => 'id_man']) }}
{{ Form::label('id_man', 'M.', ['class' => 'form-check-label']) }}

{{ Form::radio('name', 'Mme', '', ['class' => 'form-check-input', 'id' => 'id_female']) }}
{{ Form::label('id_female', 'Mme', ['class' => 'form-check-label']) }}

On the Radio Input, before the options array, add an empty option '' or 'true' for selecting by default.
Work on V 5.7 and 6

from html.

tshafer avatar tshafer commented on July 18, 2024

We accept pull requests.

from html.

marcusmoore avatar marcusmoore commented on July 18, 2024

I can work on this but I would like to know what you would expect to happen if a user uses the code above:

Form::radio('foo', '1');
Form::radio('foo', '2');

Some kind of a warning letting the developer know that id must be unique? Get crazy and throw an exception?

from html.

ZhangYiJiang avatar ZhangYiJiang commented on July 18, 2024

@marcusmoore88

The problem is that the function expects name = id, which is okay for most form elements, but not radio buttons. Radio buttons work because they all have the same name, but must not have the same id if you want to connect them to label elements. Most developers write

<label><input type='radio' [...] /> Label for this option</label>

thus obviating the need for the input element to have an id anyway.

Two Proposals:

  1. Drop the automatically generated id. This will force developers to add in id through the options parameter if they need it
  2. Append the value of the radiobutton to the given name to generate a unique id for each radio button

Both will likely break existing HTML generated with this function, but then again the existing HTML generated is already broken.

from html.

arthurkirkosa avatar arthurkirkosa commented on July 18, 2024

A combination of the two will satisfy most people. Have a default and have the option to overwrite it.

from html.

ZhangYiJiang avatar ZhangYiJiang commented on July 18, 2024

I noticed that if you pass in an id over the options parameter, the function will prefer that to the one it tries to generate. So for now I'm passing ['id' => NULL] as the fourth parameter. It's not ideal - the function shouldn't be generating broken HTML by default, but it works well enough.

from html.

adamgoose avatar adamgoose commented on July 18, 2024

The simplist solution here, for the time being, is to not use the Form::label() method for this particular checkbox. Since it's simply an HTML helper, try using raw HTML <label> tags, and the form builder will not add the ID to the element.

from html.

Related Issues (20)

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.