Struggling to make Radio Buttons function properly within an ng-repeat loop while using font-awesome icons as labels

I am facing some difficulties with implementing Font Awesome icons for radio buttons in an AngularJS ng-repeat. I have tried different solutions that involve using $parent within the ng-repeat, but none of them have worked for me so far. It is important for me to maintain the functionality of toggling the radio buttons when clicking on a row.

JSFIDDLE: http://jsfiddle.net/U3pVM/16692/

HTML

<div ng-app>
    <div ng-controller="TodoCtrl">
        <div class="container-fluid">
            <div class="row" ng-repeat="i in integrations" ng-click="$parent.isChecked = !$parent.isChecked">
                <div class="col-xs-1">
                    <input id="int{{$index}}" type="radio" ng-model="$parent.isChecked" name="radiointegration" ng-value="i.isChecked" />
                    <label for="int{{$index}}"></label>
                </div>
                <div class="col-xs-6" style="padding-top:10px">{{i.text}}</div>
                <div class="col-xs-5" style="padding-top:10px">{{i.isChecked}}</div>
            </div>
        </div>
    </div>
</div>

JS

function TodoCtrl($scope) {
    $scope.integrations = [{
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }];
}

CSS

.row:nth-of-type(even) {
    background: #f3f8fe;
}
input[type=radio] {
    display: none;
}

input[type=radio] + label:before {
    font-family: FontAwesome;
    display: inline-block;
}
input[type=radio] + label:before {
    content: "\f1db";
}

input[type=radio] + label:before {
    letter-spacing: 10px;
}

input[type=radio]:checked + label:before {
    content: "\f00c";
    color: $harmonyColorGood
}

input[type=radio]:checked + label:before {
    letter-spacing: 5px;
}

label {
    margin-top: 7px;
    margin-left: 10px;
    font-size: 25px;
}
label:hover,
.row:hover {
    cursor: pointer;
    background: #f5f5f5;
}

Answer №1

It appears that you have mistakenly treated your radio buttons as checkboxes.

I have cleaned up some unnecessary variables in your code snippet. Please verify if this is the desired outcome.

<div class="row" ng-repeat="i in integrations">
    <div class="col-xs-1">
        <input id="int{{$index}}" type="radio" ng-model="$parent.checked" name="radiointegration" ng-value="i.text" />
        <label for="int{{$index}}"></label>

Check out the updated fiddle here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Remaining stationary as additional elements are inserted at the start of the div

I'm currently working on a chat page. Within this page, there is a div element that serves as the message container. As users scroll up, a request is sent to the server to retrieve older messages, which are then added to the beginning of the message c ...

Arranging Checkboxes Vertically in HTML Without Using Inline Styling

My checkboxes are currently displayed in a column format, but I would like them to be in a single row. To better illustrate the issue, here is a photo: https://i.sstatic.net/PxRzB.jpg I am seeking assistance on how to align the checkboxes horizontally in ...

Automatically executing JavaScript function on an AngularJS webpage

Within my AngularJS webpage, I have implemented a self-invoking function. One crucial aspect of this function is the getData() method, responsible for making Ajax calls to fetch data upon page load and user interactions. <script type="text/javascript"& ...

Exploring a Ring with Three.js OrbitControls Rotation

I am having an issue with my OrbitControls camera setup. Currently, the camera rotates around a fixed point at player.position.x, y, and z coordinates. While it works fine, I need the camera to rotate around a ring instead. In the examples provided, the fi ...

The Owl carousel seems to be malfunctioning as there are no error messages displayed and the div containing it disappears unexpectedly

I'm having an issue with Owl carousel. I've included the necessary owl.carousel.css, owl.carousel.js, and owl.theme.css files. Created a div with the class "owl-carousel", and called the function $(".owl-carousel").owlCarousel();. However, after ...

Adding PHP array to a JavaScript array

I am working with an array that contains the following data: Array ( [0] => Array ( [id] => 9826 [tag] => "php" ) [1] => Array ( [id] => 9680 [tag] => "perl" ) ) My goal is t ...

Merging elements of an array

There is a single array that holds appointmentID (first value) and supperBillID (second value) separated by a comma. The AppointmentID will always be unique, but the superBillID can be repeated in consecutive positions. The goal is to create an array that ...

Effortless Registration and Authentication using Ionic with Firebase

Recently, I embarked on my journey to learn Ionic. I'm seeking some guidance on how to incorporate Login and Sign-up features using Firebase in Ionic. Any assistance would be greatly appreciated! ...

I am experiencing an issue with applying responsiveFontSize() to the new variants in Material UI Typography

I am looking to enhance the subtitles in MUI Typography by adding new variants using Typescript, as outlined in the documentation here. I have defined these new variants in a file named global.d.ts, alongside other customizations: // global.d.ts import * a ...

The "div width 100%" property functions flawlessly when tested locally, yet fails to operate on the live server

Hello, I recently launched my new website at www.leafletsdistributors.com. However, I'm encountering an issue with the Get in touch section (the light grey colored area). Despite setting the width to 100%, it's not fully extending across the scre ...

How can I remove the popover parents when clicking the confirm button using jQuery?

I am having trouble sending an AJAX request and removing the parent of a popover after the request is successful. I can't seem to access the parent of the popover in order to remove it, which is causing me some frustration. // Code for deleting w ...

Retrieving information from AngularJS modal window

Seeking a solution to retrieve data FROM modal to invoking controller, as most examples only cover sending data TO the modal. What is the proper method for achieving this? Here is the form used within the modal: <form class="form-horizontal"> < ...

Troubleshooting: Configuring dynamic minimum time for <input type='time'> in AngularJS not functioning as expected

Can someone help me with setting the minimum time dynamically to the current time? For some reason, it's not working and I'm not getting any error messages. Where did I make a mistake? $scope.mintime = new Date(); <label class="item item-in ...

Adjusting AngularJS scroll position based on key presses

I am currently working on an autocomplete feature using AngularJS. I seem to be experiencing a problem with the scrollbar behavior. In the interactive gif provided, you can observe that the scrollbar remains stationary when navigating with the arrow keys. ...

Column-oriented and Slim-fit packaging

I have been working on designing a layout with a fixed height that will display multiple columns of specified size to accommodate flowing text. While I have successfully implemented this, I am facing an issue where the enclosing div does not adjust its siz ...

Is the Ajax call being triggered unexpectedly?

I've been working on an Ecommerce website and everything was going smoothly until the update_cart (quantity) code started submitting my form instead of updating it. I've tried making changes and even moving it outside the form, but the issue rema ...

IE has trouble with CSS inline-block and width-auto styling, leading to incorrect rendering

Recently, I've noticed a strange behavior in Internet Explorer 9-11 and Edge (Spartan). In all browsers except for IE, my example displays as desired: However, in Internet Explorer, it looks different: I used to encounter this issue on multiple bro ...

How can a Bootstrap card be designed with the image positioned at the top left, but adjusting based on different

When it comes to Bootstrap 4 cards with images, most have the image positioned at the top using .card-img-top. But what if you want the image to be at the left or at the top depending on the width? Currently, I have two types of cards - one with the image ...

Having trouble with PHP's json_decode function with GET variables in an object?

I am currently working with an angular code that utilizes jsonp. One issue I am encountering is related to the object variable 'o_params' in my params. Here is the javascript code snippet: $http({ method: 'JSONP', ...

My Angular ng-repeat isn't reflecting changes made by a custom filter

My ng-repeat is filtering out items based on a category selected by the user, but when the page loads with the default 'all' category, none of the items are filtered. There are three categories available and the selected category is passed into a ...