Can a checkbox in Contact Form 7 be disabled? - wordpress

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!

Related

Validation for Kendo AutoComplete when user does not select the value

I want the validation for kendo AutoComplete when user does not select any value from AutoComplete Value that is populated.
For Little Bit background say I do have two controls one as Kendo AutoComplete and other is Input box if user types something in the AutoComplete the values is populated and he does not select any value and switch to next control it must give a validation message that please select the value from the AutoComplete.
and Also if the user type any string in the AutoComplete and Switch to next control it must also give the validation that "hey,this value is not in the AutoComplete" so that it must not save any other data other than AutoComplete datas that is being Populated.
Heres how your auto complete is defined
#(Html.Kendo().AutoComplete()
.Name("countries")
// etc.
On submit button click event
<script>
$("#btnSubmit").click(function(){
var autoCompleteValue = $("#countries").val();
if (autoCompleteValue == "" || autoCompleteValue == null){
return false; //cancels submit action
}
// else let submit go through
});
</script>
The null check is probably useless, cuz if it doesn't have a value it's usually equal to ""
The .val() solution did not work for me, because the .val() value of the control is still the text I entered (custom text, not any of the AutoComplete values), and that's wrong.
Solution is in preventing the custom input of Kendo AutoComplete. See this link:
Kendo UI - Prevent Custom User Input in the AutoComplete

Change jQuery Tabs from DropDownList's onchange-event

how to select a jQuery Tab onchange of an ASP.Net DropDownList according to the selected value?
You could try something like this:
$("#dropdownClientIDHere").change(function()
{
onDropdownChange(this.selectedIndex);
});
function onDropdownChange(index)
{
$('#tabsElement').tabs("select" , index);
}
(disclaimer - not tested)
It'll select the tab matching the index of the selected item in the drop down list.
Also worth checking out the jQuery ui tabs documentation. The method you'll want to look at is select as used here.

Jquery validation not working after clearing a form

I have applied validation through JQuery Validation Plugin on my page. The validation works fine but once the Clear button is hit to clear out all the fields on the form, and then the save button is clicked again, the validation doesn't fire and the form gets submitted. I have called the following javascript function on click of Clear button to clear out all the form fields :-
function ResetForm() {
jQuery(':input', '#form1')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
return false;
}
The Clear button is on a ChildPage and ResetForm function is on the MasterPage. Anybody have any guess why its getting submitted after clearing the fields ?
input is an element and not a attribute or a pseudo selectable, the main issue I see in your code is the : within the :input
Try changing to jQuery('#form1 input') to fetch the list of inputs
Also change the not() command to select filter the inputs by type
.not('[type="button"], [type="submit"], [type="reset"], [type="hidden"]')
also as for :hidden there's several factors you should know about this.
They have a CSS display value of none.
They are form elements with type="hidden".
Their width and height are explicitly set to 0.
An ancestor element is hidden, so the element is not shown on the page.
In light of your comment please try this tested version:
function resetForm()
{
$("#form1").find(':input').each(function()
{
var jelem = $(this);
switch(this.type)
{
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
jelem.val('');
break;
case 'checkbox':
case 'radio':
jelem.attr('checked',false);
}
});
}
#source: http://www.electrictoolbox.com/jquery-clear-form/
Another way to do this is to create a hidden input in your form but set the type as reset like so:
<input type="reset" style="display:none" />
and then do:
function resetForm()
{
$("#form1[type='reset']").click();
}
Actually the error was something else, the code provided by RobertPitt is correct for clearing of form fields and my code was also correct for clearing of form fields. But the problem is that, on the clear button I had applied a class="cancel" so that the form should not get submitted because it was an aspx:button.
But according to what is written in JQuery docs, clicking of a button whose class is cancel should skip the validation, but after that if I click on a normal submit button validation should fire which was not firing in my case.
I just removed the cancel class and it worked.
Does this help?
Reseting the form when usering the jquery validations plugin

How to get the selected Date from the calendar control?

Hai ,
I am creating a DatetimePicker User control. I just want to know how to get the selected date of the calendar (asp.net control) control using jQuery. I used this code, but it's wrong.
$(document).ready(function() {
$(".UserCalender").click(function () {
var a = $('.CalenderDiv:selected').text();
alert(a);
});
});
What's wrong with this?
You won't be able to do like this. There is no :selected selector for an anchor tag. It works only for <option> elements. What you can do is to attach an event hanlder to each anchor ag and use the text() method. Something like
$("#Calendar1 a").click(function(){
alert ( $(this).text() );
return false;
});
But why do you want to do this. By doing like this you will get only the text inside the anchor tag and not the whole date. To get the whole date you will have to perform additional work.
If you want to manipulate the selected text then you can use any datepicker plugin from jQuery.
See jQuery UI Datepicker

How can I get value from radio-button inserted into innerHtml

I have sort of a table with a radio-button column. I managed to make radio-button column work dynamically inserting into a cell (div if matter). But, on postback innerHtml hasn't been updated with "checked" attribute.
Could you give me an idea how can I find out (on the server) if radio-button has been checked?
More info: This is on user control inside update panel.
This would be good post on my topic, still doesn't help
Any reason you cannot use a standard asp:RadioButton and use javascript to ensure it is mutually exclusive. I have done this before by adding a custom attribute to the radiobutton and then using a js function to uncheck all items with that attribute and then check the selected one. This works around the IE issue which prevents the groupname attribute from working on radioboxes that are in different containers.
radioButton.InputAttributes.Add("ClientGroupName", "grpRadioList");
radioButton.InputAttributes.Add("onclick",
string.Format(
"javascript:radiobuttonToggle('{0}','ClientGroupName','grpRadioList');"
,radioButton.ClientID));
and use the following JS to uncheck all radios and then check the one you want.
Note i used InputAttributes instead of Attributes as the radiobutton is wrapped inside a span tag so InputAttributes is for items added to the actual input control rather than the span.
function radiobuttonToggle(selectedRB, attribName, attribValue)
{
var objRadio = document.getElementById(selectedRB);
for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i];
if (elm.type == 'radio')
{
if(elm.getAttribute(attribName) == attribValue)
elm.checked = false;
}
}
objRadio.checked = true;
}
You can then expose radioButton.Checked as a property in your CS file and reuse this as a control.
Check Form.Request("radio-name") != null
You only get a non-null value when it's been checked.
Make sure your page elements are being rebuilt correctly on postback. Any binding process that inserted the radio buttons the first time around will have to be re-run before you can access them the second time.
Here is a working example, first I add radios to my webform by the method you linked :
function addRadio()
{
try{
rdo = document.createElement('<input type="radio" name="fldID" />');
}catch(err){
rdo = document.createElement('input');
}
rdo.setAttribute('type','radio');
rdo.setAttribute('name','fldID');
document.getElementById('container').appendChild(rdo);
}
Then at code behind I used only the code below to get the radio's value :
string value = Request["fldID"];
So, be sure you're trying to get the name of the radio buttons at server side. You should use name attribute at server side, not id.

Resources