How Can I Reset up Select2 Dropdown On Click Of Button? - button

I basically want to reset select2 field data not remove on click of reset button.
$(document).on("click",".reset",function(){
$("#MyId").prepend("<option value='' selected='selected'></option>");
})

To reset select2 field data:
$("#MyId").val('').trigger('change')
or
$("#MyId").empty().trigger('change')

Related

Popup Hide Show

I want to create show and hide a alert bar using (alert) button click, If i click that alert button it needs to show what is that alert & again I click that button it needs to be (Hide) visibility gone...I want to switch that visibility thats all.
How to do this in android kotlin, I am new to this field, Plz help me..
This is my code
// for alert popup
binding.alertImage.setOnClickListener {
binding.alertImage.setVisibility(View.INVISIBLE);
binding.scrollText1.visibility = View.VISIBLE
}

ngBootstrap Capture click event on typeahead suggestions

when I type 'ala' it displays 2 states in suggestions 'alabama' and 'alaska'. Now what I need is as soon as I click on 'alaska'/'alabama' any item in list it should call my method
methodAbc(){
//Some complex logic
alert("Method called.");
}
Sample code link click here
I tried blur, focus, etc events on text box they didnt work way I need. Click do not triggers on item selection it triggers when I click inside text box.
You just need to use the selectItem event from ng-bootstrap's ngbTypeAhead API
<input id="typeahead-template" type="text" class="form-control" [(ngModel)]="model"
[ngbTypeahead]="search" [resultTemplate]="rt" [inputFormatter]="formatter"
(selectItem)="methodABC($event)" />
See updated sample code

get value of checkbox on form submit in razor

I have a html form and I need to get the "checked" value of some checkboxes. The problem is that when I submit the form, the data in textfields and dropdowns works fine, but all checkboxes and radiobuttons is set to not be checked.
This is my checkbox:
<input name="chkbox" value="test" type="checkbox">Label text
This is how I try to get the value in razor on submit:
if(Request["chkbox"].AsBool()){
//its checked
}
else{
//its unchecked
}
If I set the checkbox to be checked by default I get a "checked" value on form submit.
It seems like when I check a checkbox it doesn't actually change it's checked state in the form?
What am I missing here?

Can a checkbox in Contact Form 7 be disabled?

Can a checkbox in Contact Form 7 (Wordpress plugin) be disabled?
I have a group of 5 checkboxes, and I want one to be there, but disabled (not clickable, not selected).
How to do it?
Add an id to your to your checkbox. It will look something like this, it is important that the id is after the variable as shown below.
[checkbox variable id:disablethis "variable"]
This will put the id "disablethis" on the span tag that surrounds your checkbox (input) that you are trying to disable. Then we can simply find that span and disable all of the inputs within it like so. Put this at the bottom of your form/page.
<script>
$("#disablethis :input").attr("disabled", true);
</script>
you can disable it by using jQuery like this :
jQuery('#checkbox').attr('disabled','disabled');
where #checkbox is the ID of checkbox.
Thanks a million ImTheMechanic! I was looking for a few days how to reference the checkbox and set its state (checked or unchecked).
I had to put :input after the id.
I could never have guessed!
I did it like this:
if (dayNameB == "zaterdag") {
$("#brengtijdzat").show();
$("#brengtijdzat :input").prop("checked", true);
$("#brengtijd").hide();
$("#brengtijd :input").prop("checked", false);
}`
Thanks!

Radio Buttons are not applying style dynamically

I'm trying to refresh a list of radio buttons every time a user visits the tab menu. First time visit styling is okay, but they are behaving like checkboxes and can not be unchecked when other radio buttons are clicked.
I have tried to put refresh(); method but it still doesn't work.
You can see the demo on JSFIDDLE
Any suggestion? and Thank you.
$('.export_tab').click(function(){
$("#radios_wrapper").children().remove(); //Remove all previous radio buttons
for(var i in localStorage) //Looping through the localStorage
{
dataIndex = JSON.parse(localStorage[i]).index;
dataName = JSON.parse(localStorage[i]).name;
//Then insert a new one
$("#radios_wrapper").append('<input type="radio" value="'+dataIndex+'" name="'+dataIndex+'" id="radio'+dataIndex+'"/><label for="radio'+dataIndex+'">'+dataName+'</label>');
}
});
And this is the HTML
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" id='radios_wrapper'>
</fieldset>
</div>
Radiobuttons need the same name to become a group. So:
'<input type="radio" value="'+dataIndex+'" name="'+dataIndex+'"/>'
is not the right way. The name should be the same for all radios you want to group. It should be:
'<input type="radio" value="'+dataIndex+'" name="allTheSame"/>'
Here is an update to your Fiddle.
To tell jQuery to redraw use the trigger function like .append('whatever').trigger('create'). http://jquerymobiledictionary.pl/faq.html. Updated Fiddle.

Resources