Ionic 5, ionic checkbox so late behavior - javascript

I tried to bind checked attribute value on ion-checbox but the behavior is a bit late.
On my ts file I have an array variable user_id and on my checkbox list i put an action to fill this array depend on which checkbox is checked, and then verify to make the value of checked attribute:
<ion-checkbox [checked]="user_id.includes(user.id) ? true : false" (click)="AddUser(user)"><ion-checkbox>
the user_idis filled and the value of checked change but the checkbox seem not checked, and when i tried to recheck the checkbox, the value change to false but the checkbox seem checked.
I've put some functionality to make condition (example variable type)if the value is true so the checkboxlist is not shown, and with that functionality, when the value of type switch from false to true, the checkbox work well but the behavior is bit late at the moment when the checbox is checked for the first time
TL;DR
click event is working properly with my checkbox and retrieving data is not consistent

Please refer to Ionic documentation on ion-checkbox
using the (click) to capture the action on a checkbox is wrong.
I suggest you use (ionChange) event to trigger your addUser() function.
With [(checked)] binding, it will create an automatic sync between your actions and the values you save.

Related

Unable to check and uncheck the dynamically rendered checkboxes in react

I am iterating over the permissions and make checkbox checked if permission included in a predefined values(i.e val) and make checkbox unchecked otherwise, which it did well, but when I click the rendered checkboxes to check or to uncheck it do nothing.
I can't check or uncheck after I rendered my checkboxes. I need your help , thanks.
Your role.permissions is never getting updated, so the checkbox checked attribute stays as its initial value. Are you using controlled components? If so, you can add an onChange event handler to your input to update your role.permissions.
Firstly, the ternary operation in checked={role?.permissions?.includes(val[i]) ? true : false} is redundant and can be simplified to just checked={role?.permissions?.includes(val[i])}, since the value of that property will be either true or false anyway.
Secondly, by setting value= to true or false, you are freezing the checkbox to that value. You can omit that setting, as the value attribute will be submitted according to the checked or unchecked value. Also, typically you assign value=checked or value=unchecked, not true and false.
use map function and useState to control your checkbox values.

Keep checkbox unchecked until onclick function returns true with AngularJS

Using AngularJS framework, in my HTML code I have this checkbox:
<input type="checkbox" ng-checked="switch.isOn()" ng-click="SwitchController.setValue()">
When clicked, the checkbox is checked/unchecked before the setValue function get executed. I want the checkbox not to be checked if the setValue() function returns false value.
You can use ng-true-value and ng-false-value along with ng-model.
If you get false value from your function just set the ng-model to constant you've specified in ng-false-value.
Also you can use ng-disabled and set it true for the duration between right after entering the SwitchController.setValue() and the same function returning the value to prevent unwanted clicks.
This won't exactly delay the clicking of checkbox but should get you the desired end result.

how watch to change angularjs model which checkbox changed from jquery

I use https://github.com/Dimox/jQueryFormStyler for styling form inputs.
I set the property ng-model="c.model.acept".
If I click on "styled checkbox", then input gets to property "checked", but the angular model still has the old value.
I tried to trigger the change event with no result.
If I trigger the click event, then the checkbox gets changed twice (once from click, and then the second time from the triggered click event).
How to fix it?
You can not change "ng-model" of particular input field conditionally.
In this condition what you can do is, keep two input field and use "ng-show" or "ng-if" attribute to show & hide input field conditionally.
Hope this will hep you.

Need to find where my radio option CHECKED value gets changed

Is there way that i could identify where a radio option value gets changed, either thru watch expression on firebug or inspect element ?
i am remote debugging a website and there are 4 radion buttons in the website. We set the CHECKED property for my 4th option as true, it gets checked. But after a sometime(1 sec) my first option gets selected automatically. There are too many javascript code involved and i am not sure where to check.
So is there any way i can do a debug-BREAK when a watch expression fires or any other way to debug this?
You can do this using jquery:
$('input[type=radio][name="inputName"]').on('change',function(){
//#myForm is the id of the form that the radio box in
alert($('input[name="inputName"]:checked', '#myForm').val());
});
This will alert the new value of the radio box when changed JsFiddle

How can I know if the user selected the same item in a select box

I have a select box that needs to act even if the user selects the currently selected item. I have used onChange (via JQuery) but it doesn't fire if the same item is selected because it hasn't changed.
Is this even possible?
I'm not sure i understand your question clearly cause of my English. You want to know when a checkbox is clicked if it is already checked you want to fire a function. If i'm right then you can do it in many ways. E.g If you have 2 classes for your checkbox checked or unchecked you can look if that checkbox got "checked" class with .hasClass or you can store index of a checkbox in an array when it is clicked, and every click on a checkbox you can search array if that array has index of that checkbox. If result is true, you fire your function.
You can try in each of your select box to include the onclick event and call your desired function when that happens.
Or you can use the onblur event in your element and fire your function when that happens.

Categories