ValidationGroup issue - without group: `DoPostBackWithOptions`, with group: `__dopostback` - webforms

Validation works fine until I make use of ValidationGroup. Afterward the form submits but no validation occurs. This is the href on the LinkButton before and after I use the ValidationGroup.
Before: javascript:DoPostBackWithOptions(...)
After: javascript:__doPostback(...)
The CausesValidation property is set to true. Why does adding the ValidationGroup change the postback code like that?

Once you set the validationgroup on the button, the button should only trigger the matched group validator.
ASP.Net generates WebForm_DoPostBackWithOptions is because there is a group validator on your page matching with your button's attribute ‘validationGroup’.
Your link button markup code should be similar like that:
<input type="submit" name="btnGroup1" value="Group1" onclick="javascript:WebForm_DoPostBackWithOptions(
new WebForm_PostBackOptions('btnGroup1', '', true,'Group1','', false, false))" id="btnGroup1" />
Through debugging the js code, you should be able to find there is a js function used to find group validator. This function will validate if 'Group1' validator is there.
Debug this js method see if it can find your specified group validator.
IsValidationGroupMatch

Related

Spring MVC checkbox with Materializecss

I am using Spring MVC checkbox with materialize css and it is not showing up at all.
Here is what i am doing. i am using simple checkbox in jsp like this (without materializecss).
<form:checkbox path="nameID" value="store" id="nameid_3" />
Checkbox gets displayed correctly.Now when i embedded materializecss, checkbox does not appear on the screen.
So i went further to check what is really going on behind the wall and found this.
<input id="nameid_3" name="nameID" type="checkbox" value="store" checked="checked"><input type="hidden" name="_nameID" value="on">
Checkbox with hidden field and that's the problem.
When i deleted this hidden field in inspect element in chrome it worked.
So now questions how do i stop generating this hidden field with Spring MVC tag..? or is there alternate approach..?
and i am bound to use Spring MVC tag for validitions.
I found an alternate approach to remove these hidden fields. As we can see, there is a linking between name of checkbox and its hidden element. As we can see these field names are differentiated only using underscore. So we can remove these hidden fields using jQuery like this.
$('input[type=checkbox]').each(function() {
var name = $(this).attr('name');
$('[name="' + '_' + name + '"]').remove();
});
Hope this solves your problem.

kendo ui, angular require validation for numeric text box

I am trying to use a kendo numeric text box with angular validation (ng-required) however I'm not able to get it working. The ng-required attribute on this element has no effect on the form validation status.
From my understanding, the reason why this doesn't work is because kendo numeric text box uses k-ng-model to store it's value, whereas the angular validation works only with ng-model.
Has anyone else seen this issue, are there any workarounds?
I have found a workaround that involves using the kendo-numeric-text-box along with a hidden input field which makes use of ng-model.
<input data-kendo-numeric-text-box data-k-ng-model="numValue"/>
<input type="hidden" data-ng-model="numValue" data-ng-required="true" />

CakePHP Prototype Ajax Checkbox disable onCreate onComplete events

I have two checkboxes in my code as mentioned below:
<input type="checkbox" id="event_id" name="data[Noncompetitor][event_id][]" value="1">
<input type="checkbox" id="event_id" name="data[Noncompetitor][event_id][]" value="2">
Now I am doing Ajax function like onCreate and onComplete, where I want to disable checkboxes when its initiated and want to enable again as completed request. I am not sure how that can be achieved in Prototype JS and both above checkboxes have same id.
onCreate: function(){
document.getElementById("event_id").setAttribute("disabled", "disabled");
Element.show('loading_message');
},
onComplete: function(){
document.getElementById("event_id").removeAttribute("disabled");
Element.hide('loading_message');
},
My Above code works, but it disables only first checkbox, so please help me here.
Thanks !
You can't have two ids of the same in a HTML page, nothing is stopping you from putting two ids of the same in a HTML page you can but you kill a kitten everytime you do that, and furthermore having two ids will confuse yourself in cases like this. document.getElementById would return the first id it finds and stop caring about the other everytime you have two ids of the same in a HTML page, thus why it only works for one checkbox.
You can either assign classes to your checkboxes, or you can reference your checkbox using name attribute if your form is also named.
http://jsfiddle.net/Q5qNg/7/

CodeIgniter: set_checkbox problem

I seem to be running into something really nasty:
I have a form which contains a group of checkboxes.
I have set up validation rules for my form, and just added an empty one
for my checkbox group. However, after validating my form and giving an error,
it only rechecks the last one in the group that was selected. This is just
driving me nuts, since the user will never notice it was unchecked!
for now, before building up the system, I just hardcoded the form to check if it works
how I want it to work.
<fieldset>
<legend>Locaties veldwedstrijden</legend>
<?php echo form_checkbox('locatie','oudenaarde', set_checkbox('locatie','oudenaarde'));?>3-7-2011 te Oudenaarde <br />
<?php echo form_checkbox('locatie','arendonk', set_checkbox('locatie','arendonk'));?>31-7-2011 Arendonk<br />
<?php echo form_checkbox('locatie','westdonk', set_checkbox('locatie','westdonk'));?>11-09-2011 Westhoek – MERKEN<br />
</fieldset>
It also has this validation rule in it:
array('field' => 'locatie','label' => '','rules' => ''),
Can anybody tell me what I'm doing wrong? I read the whole manual, but I can't
find the slightest hint of what might be wrong with this code...
You're using a checkbox like a radio button. No matter how many checked checkbox, they're all named locatie, php will only see one value.
If you wanted to save multiple values from the checkbox, you'd either need to use a different name for each checkbox (locatie1, locatie2, locatie3) or use a php style name array (locatie[]). I'm not sure for the latter that the CI form helper function will work properly with that style of naming though.

Values of disabled inputs will not be submitted

This is what I found by Firebug in Firefox.
Values of disabled inputs will not be submitted
Is it the same in other browsers?
If so, what's the reason for this?
disabled input will not submit data.
Use the readonly attribute:
<input type="text" readonly />
Source here
Yes, all browsers should not submit the disabled inputs, as they are read-only.
More information (section 17.12.1)
Attribute definitions
disabled [CI] When set for a form control, this Boolean attribute
disables the control for user input. When set, the disabled attribute
has the following effects on an element:
Disabled controls do not receive focus.
Disabled controls are skipped in tabbing navigation.
Disabled controls cannot be successful.
The following elements support the disabled attribute: BUTTON, INPUT,
OPTGROUP, OPTION, SELECT, and TEXTAREA.
This attribute is inherited but local declarations override the
inherited value.
How disabled elements are rendered depends on the user agent. For
example, some user agents "gray out" disabled menu items, button
labels, etc.
In this example, the INPUT element is disabled. Therefore, it cannot
receive user input nor will its value be submitted with the form.
<INPUT disabled name="fred" value="stone">
Note. The only way to modify dynamically the value of the disabled
attribute is through a script.
You can use three things to mimic disabled:
HTML: readonly attribute (so that the value present in input can be used on form submission. Also the user can't change the input value)
CSS: 'pointer-events':'none' (blocking the user from clicking the input)
HTML: tabindex="-1" (blocking the user to navigate to the input from the keyboard)
They don't get submitted, because that's what it says in the W3C specification.
17.13.2 Successful controls
A successful control is "valid" for submission. [snip]
Controls that are disabled cannot be successful.
In other words, the specification says that controls that are disabled are considered invalid for submission.
There are two attributes, namely readonly and disabled, that can make a semi-read-only input. But there is a tiny difference between them.
<input type="text" readonly />
<input type="text" disabled />
The readonly attribute makes your input text disabled, and users are not able to change it anymore.
Not only will the disabled attribute make your input-text disabled(unchangeable) but also cannot it be submitted.
jQuery approach (1):
$("#inputID").prop("readonly", true);
$("#inputID").prop("disabled", true);
jQuery approach (2):
$("#inputID").attr("readonly","readonly");
$("#inputID").attr("disabled", "disabled");
JavaScript approach:
document.getElementById("inputID").readOnly = true;
document.getElementById("inputID").disabled = true;
PS disabled and readonly are standard html attributes. prop introduced with jQuery 1.6.
<input type="text" disabled />
instead of this disabled use readonly
<input type="text" readonly />
Disabled controls cannot be successful, and a successful control is "valid" for submission.
This is the reason why disabled controls don't submit with the form.
select controls are still clickable even on readonly attrib
if you want to still disable the control but you want its value posted.
You might consider creating a hidden field. with the same value as your control.
then create a jquery, on select change
$('#your_select_id').change(function () {
$('#your_hidden_selectid').val($('#your_select_id').val());
});
Here's the Solution and still using disabled property.
First disable your inputs on load.
$(document).ready(function(){
$("formselector:input").prop("disabled",true);
$( "formselector" ).submit(function( event ) {
$(":disabled").prop("disabled",false);
});
});
on submit enable all of them. this will assure everything is posted

Resources