Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How to fix Radio Form in Angular.js with inner div

My form is structured like the following:

<form class="content">
  <div class="inner-content" ng-repeat="item in items">
    <span class="inner-content-name">{{item.name}}</span>
    <input
      class="inner-content-toggle"
      ng-class="{{item.className}}"
      type="radio"
      ng-click="toggle(item.id, item.name)"
      ng-checked={{item.checked}}
    />
  </div>
</form>

My question is more of why this does not work... When I click on one of the radio buttons in the rendered UI it adds the inner dot, however the inner dot when clicked again does not go away and stays permanently. As well if I select another radio button while one is already clicked both are now clicked and both will not unclick. This behavior is very much like a checkbox, but I want only one to be clicked ever. Any suggestions?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You must set the name attribute with the same value for the radio elements if they are mutually exclusive.

For example try this:

javascript:

this.items = [
    {
        name: 'foo',
        nameAttr: 'radio-option1',
        className: 'foo-bar',
        checked: 1
    },
    {
        name: 'bar',
        nameAttr: 'radio-option1',
        className: 'foo-bar',
        checked: 0
    }
];

html:

<form class="content">
  <div class="inner-content" ng-repeat="item in $ctrl.items">
    <span class="inner-content-name">{{item.name}}</span>
    <input
    class="inner-content-toggle"
    name="{{item.nameAttr}}"
    ng-class="{{item.className}}"
    type="radio"
    ng-click="$ctrl.toggle(item)"
    ng-checked="item.checked"
  />
  </div>
</form>

Playground: https://stackblitz.com/edit/angularjs-qhcken?file=home/home.controller.js

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda