The function ng-click does not successfully uncheck ion-radio

In the process of developing my application using the ionic framework, I encountered a challenge where I needed to deselect an ion-radio button when clicking on an input tag. Despite attempting to achieve this functionality through this ionic play link, I was unable to do so successfully.

HTML

<ion-content class="padding">
    <label class="item item-input">
      <div class="input-label">
        <i class="ion ion-search"></i>
      </div>
      <input ng-click="uncheck($event)" type="text" ng-model="foodfilter" class="">
    </label>
    <ion-radio ng-model="filter.typefilter" ng-value="'A'">Choose A</ion-radio>
    <ion-radio ng-model="filter.typefilter" ng-value="'B'">Choose B</ion-radio>
    <ion-radio ng-model="filter.typefilter" ng-value="'C'">Choose C</ion-radio>
  </ion-content>

JS

$scope.uncheck = function (event) {
 if ($scope.filter.typefilter == event.target.value) $scope.filter.typefilter = false
}

Check out the ionic play link for more details

Answer №1

Make sure to implement ng-click on your input element for better functionality.

<input ng-click="uncheck($event)" type="text" ng-model="foodfilter" class="">

Remember that the value of filter.typeFilter is a string, so use value instead of ng-value.

<ion-radio ng-model="filter.typeFilter" value="A">Choose A</ion-radio>
<ion-radio ng-model="filter.typeFilter" value="B">Choose B</ion-radio>
<ion-radio ng-model="filter.typeFilter" value="C">Choose C</ion-radio>

To clear the radio boxes, simply set the value of ng-model to an empty string.

$scope.filter = {
    typeFilter: ""
}

$scope.uncheck = function (event) {
    $scope.filter.typeFilter = "";
}

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

What causes an asynchronous function to exhibit different behavior when utilized in conjunction with addEventListener versus when manually invoked?

I was delving into the concepts of async and await keywords and decided to create a basic demonstration using an HTML file and a corresponding JS file. In my example, I defined two promises - promise1 and promise2. The handlePromises function uses async/ ...

Error during compilation in npm (symbol '_' is not recognized)

After updating all the dependencies in my JavaScript program without making any changes to my components, I encountered an error when running: npm run build The error specifically mentions a problem with one of my components: Failed to compile. ./src/c ...

Encountering a TypeError while trying to import grapesjs into a nextjs project, specifically receiving the error: "Cannot read properties of null (reading 'querySelector')

I encountered an issue while trying to integrate grapesjs into a nextjs project. The error I received was TypeError: Cannot read properties of null (reading 'querySelector') It appears that grapesjs is looking for the "#gjs" container by its id ...

Present information using Vue.js

Struggling to display just the name from the request object in my form using JavaScript. I'm new to working with JS and need some guidance. I attempted to use {{ request.name }}, but it's not functioning as expected. When I tried {{request}}, it ...

"Oops! Vite seems to be facing an issue as RefreshRuntime.injectIntoGlobalHook function is

Our CRA react app has been transitioned from webpack to Vite. Problem: When running the application locally in production mode, I encounter the following error: 1. Uncaught TypeError: RefreshRuntime.injectIntoGlobalHook is not a function at (index):6:16 ...

At which point in the MEAN stack should validation rules be established?

As I work on an application developed with the MEAN stack, there is a significant amount of form data input that needs to be stored in the database by both authenticated and unauthenticated users. I'm unsure about where to implement all my validation ...

Updating the dynamic site script to be compatible with the newest version of the jQuery library

After finding a script on http://css-tricks.com/dynamic-page-replacing-content/, I decided to edit it to suit my needs. Initially, everything worked perfectly with "jquery-1.4.4". However, when I tried using versions later than "jquery-1.5", the active cla ...

Execute a simulated click on the Material-UI Tabbar using a programmatic approach or keyboard shortcut

In my electron/react application, I am implementing Material UI tabs in the following manner: <Tabs> <Tab label="View1" > <View1 /> </Tab> <Tab label="View2"> ...

Tips for resolving the error message "cannot read property of undefined"

I've been working on coding a Discord bot and I keep encountering an error when trying to check if "mrole" has the property "app". It's not functioning as expected and I'm puzzled by why this is happening. My intention is to retrieve the te ...

The ng-view directive appears to be malfunctioning

index.cshtml <head> <meta name="viewport" content="width=device-width" /> <title></title> <script src="~/Scripts/angular.min.js"></script> <script src="~/Scripts/angular-route.min.js"></script ...

What is the best way to show a message within a specific HTML division with JavaScript?

Here's my attempt at solving the issue: <head> <script> function validateForm() { var username = document.forms["login"]["uname"].value; var password = document.forms["login"]["pwd"].value; if (username == "" || p ...

What is the best way to incorporate spacing between rows in material UI and React?

How do I add spacing between each row in my table using MUI? I've tried using borderSpacing: '0px 10px!important' and borderCollapse: 'separate!important' but it's not working. Any suggestions on how to achieve this with MUI w ...

Utilize the identical function value within a Vue template

In my template, I am encountering a recurring situation where I need to retrieve a value from a function. This function takes parameters from the template (such as the index of a v-for loop) and returns a result that is then displayed on the template. The ...

best practices for implementing authentication in MEAN stack

Currently, I am exploring the most effective approach to develop an authentication system that is straightforward (relying on a user_name and password). After researching best practices, I came across several projects; however, most of them are outdated a ...

tips for dynamically highlighting search bar after choosing a different dropdown option - vuejs

I need to filter products in my application based on name and category. To achieve this, I have included a search text box and a dropdown select box. The dropdown select box offers two options: 1. Search products by name 2. Search products by category name ...

Using JavaScript, is there a way to modify a JSON parameter within an API?

My API provides JSON data structured like this: [{"NAME":"john","SURNAME":"johny","ADULT":"3","CHILD":"3","BABY":"0",}] In my JavaScript function, I need to send a request to a web service that will update the value of "BABY" from "0" to "1". Can this be ...

Is jQuery necessary for Breeze to work in conjunction with AngularJS?

I could use some clarification on using Breeze. I've gone over the documentation but couldn't find a solution to this. If I'm incorporating Breeze with ASP MVC4 and AngularJS, do I need to load the jQuery script as well? ...

MUI - Material-table/core - Checkbox selection malfunctioning on click event

UPDATE : The matter also pertains to Material Ui's Data table. I attempted to replicate the issue using the provided example in the documentation but encountered the same problem. I have been struggling with an issue related to the selection feature ...

Steps for removing the console warning message: "The use of enableRowSelect has been deprecated. Instead, please utilize rowSelection."

) I have integrated React Data Grid from https://adazzle.github.io/react-data-grid/ multiple times in my application. One thing I noticed is that there is a console warning related to a prop called "enableRowSelect" which indicates whether the prop is bein ...

Utilizing the fs module in Node.js

Hello friends! Currently I am faced with an issue while trying to import the fs module in nodejs. Initially, I utilized require to import it like so: const fs = require('fs'); Everything was functioning smoothly until recently when it suddenly ...