Giter Site home page Giter Site logo

Comments (4)

scrnjakovic avatar scrnjakovic commented on May 11, 2024

The way radio buttons work in Phalcon, as far as I got them, is:
Form initialization

$this->add(new Radio('published'));

View

{{ form.render('published', ['value':'Y'])  }}
{{ form.render('published', ['value':'N'])  }}

from phalcon.

kornerita avatar kornerita commented on May 11, 2024

Hi @scrnjakovic,

I think that's kind of a hack since, it's rendering de same component twice with different values.

i.e. you can't set two different labels.

Gender:
(x) Male ( ) Female.

You can't use:

Gender: <br>
{{ form.render('gender', ['value' : 'M']) }}: {{ form.label('gender') }} 
{{ form.render('gender', ['value' : 'F']) }}: {{ form.label('gender') }} 

from phalcon.

scrnjakovic avatar scrnjakovic commented on May 11, 2024

Well, sort of. It is hacky when it comes to labels, whereas it is quite valid when it comes to the input itself. I do generally agree with you, but that wouldn't solve the issue. I wish I had more time to dedicate to this discussion, but I would like to ask you to write an example code to render a radio and labels for the following use cases:

  1. Gender: (x) Male ( ) Female
  2. (x) I agree ( ) I do not agree (note missing third label)
    and in the process you will see what I meant.

Radios and checkboxes are conceptually completely different than other input controls and I think that the design of Phalcon\Forms\Element, a base class of all elements, does not support that. It goes beyond ID/Name.

P.S. This is how I use it, and we have the same particular case:

{% set genderElement = form.get('gender') %}

{{ form.label('gender', ['for': '']) }} // Gender label

{% do genderElement.setLabel('Male') %}
{{ form.render('gender', ['id': 'male', 'value': 'M']) }}
{{ form.label('gender', ['for': 'male']) }}

{% do genderElement.setLabel('Female') %}
{{ form.render('gender', ['id': 'female', 'value': 'F']) }}
{{ form.label('gender', ['for': 'female']) }}

stripped HTML and attributes for simplicity

from phalcon.

niden avatar niden commented on May 11, 2024

Closing in favor of phalcon/cphalcon#13855. Will revisit if the community votes for it, or in later versions.

from phalcon.

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.