Based on the backend data i may have n number of items displayed along with the check box and textarea for selecting and give commnet on the page and there is also a option given to the user to remove the items based on the requirements. I need to set a validation like atlease one item is required.
Since its number is based on the query dont know how to set the validation.
It's hard to say without a bit more detail, but in general if you have a set of checkboxes and you want to make sure at least one is checked you could do this in your HTML:
<p><input type="checbox" name="my_field_name[]" value="item1" />Item 1</p>
<p><input type="checbox" name="my_field_name[]" value="item2" />Item 2</p>
<p><input type="checbox" name="my_field_name[]" value="item3" />Item 3</p>
and just set a rule that "my_field_name" is a required field. That's assuming it works for you to have the values returned in one array like that.
Related
I am very new to apex and just start to study how to add validation on the field. I am not able to do this from set up. In more detail I want to assign an id to apex:inputfield. I read a lot of information in the internet such as using partial id like http://www.kineticgrowth.com/javascript-visualforce-jquery-partial-id-selectors/
However know matter what I add in apex page, it doesn't show up inside the string. Here is my code:
<apex:pageBlock id="pageBlock" ...>
...
<apex:dataTable ... id="transTableBrandPurchase" ">
...
<apex:inputField id="eric_test" value="{!varBla}" required="true" />
when I check the browser in html it gets
<input id="j_id0:j_id6:pageBlock:transTableManufacturerPurchase:0:j_id273" maxlength="255" name="j_id0:j_id6:pageBlock:transTableManufacturerPurchase:0:j_id273" size="20" type="text">
Based on Salesforce reference I should get id="j_xxx:j_yyy ...:pageBlock:transTableManufacturerPurchase:eric_test"
People may say that I can just use "pageBlock:transTableManufacturerPurchase", I cann't because in this page we display then rows and the other rows look like similar:
<input id="j_id0:j_id6:pageBlock:transTableManufacturerPurchase:0:j_id275" name="j_id0:j_id6:pageBlock:transTableManufacturerPurchase:0:j_id275" >
Right now I am working on validation in visualforce page with Jquery.
My approach to assigning ID to elements in VF page is, give ID to all apex elements. Then use chrome inspect element option to find exact ID.
If you are using salesforce any repeat tags , , etc, salesforce will add additional numbering on your ID, to make sure that all elements have unique ID.
I have a textbox for Age:
<input type="text" id="txtAge" name="txtAge" class="text" placeholder="Age (optional)" maxlength="2">
Upon clicking submit, this input is instantly bordered red. There is no postback. I'm assuming IE10 believes the client has actually typed in "Age (optional)" which is greater than the maxlength of 2.
Is there anyway to get around this without making the user do anything in their browser's settings and without removing the maxlength attribute?
You can use the novalidate and formnovalidate attributes. See this link for more information.
Internet Explorer 10 and Windows Store apps using JavaScript add new support for HTML5 Forms, including new states of the type attribute (on the input element), new attributes for the input element, and the progress element. This support enables developers to quickly and easily provide user prompting, input validation, and feedback with a minimal amount of script.
Source: http://msdn.microsoft.com/en-us/library/ie/hh673544(v=vs.85).aspx
I faced same problem.
In this case you should change your max length to 10 so it will not be issue for max length and set the max length that you want for your textbox using javascript like following.
function setMaxLength(obj, len) {
return (obj.value.length < len);
}
and call this function like following
<input type="text" id="txtAge" name="txtAge" class="text" placeholder="Age (optional)" maxlength="10" onkeypress="return setMaxLength(this,2);">
This will resolve your issue.
I had the same issue, in my case it was a GUID field, which was hidden as I didn't need to have it displayed on screen. So I had display:none and maxlength=0.
Yet, IE was performing the validation, the postback was failing and I had no idea why.
It took me half day to figure it out, the solution was to set maxlength=36.
I am using the MvcContrib Grid to display a table on the page. I am using a custom column to produce a checkbox on the table so that the user can select multiple rows and submit the form.
I don't want the form to submit unless at least one checkbox has been selected. I could easily write this Javascript myself to enforce the validation, but I wanted to know how I could fit it in with the unobtrusive library supplied with MVC3.
I imagine I just need to set my inputs with the proper classes and attributes and then the scripts (validate and validate.unobtrusive) on the page should pick them up and mark them as needing validation, but I haven't been able to get the right combination thus far.
Here is the input that I am currently generating:
<input type="checkbox"
name="foo"
value="#item.foo"
class="input-validation-error"
data-val-required="Please select an option."
data-val="true" />
Try setting the data-val attributes on the item, then you have to tell jQuery you have new content to re-parse the form via something like:
$.validator.unobtrusive.parse($('#yourForm'));
where form is of course a reference to your form element.
There is also this great posting and jQuery has a few internal adapters you can call:
from http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2
jQuery.validator.unobtrusive.adapters.addSingleVal("notequalto", "otherproperty", "mynotequaltofunction")
From my experience, a commonly overlooked mistake with displaying client-side validation is putting a Html.ValidationMessageFor(lambda) on the page.
Without that, no client-side validation will fire to prevent the form submit and/or display the message that is generated using annotations on the client-side.
Hope this helps.
<div class="editor-field">
<input class="text-box single-line"
data-val="true" data-val-number="The field Qty Available must be a number."
data-val-range="The field Qty Available must be between 0 and 120."
data-val-range-max="120" data-val-range-min="0"
data-val-required="The Qty Available field is required."
id="QtyOnHand" name="QtyOnHand" type="text" value="12" />
<span class="field-validation-valid" data-valmsg-for="QtyOnHand"
data-valmsg-replace="true"></span>
</div>
The tie-in between the data model annotations and the data-val-* attributes should be clear after reading the above code, but it's where the client side validation ties in might not be so obvious. Open the \Scripts\jquery.validate.unobtrusive.js file and search for "data-val". Right away you'll see that the JavaScript uses the data-val-, input- and field-* CSS classes to display/hide validation messages on the client.
The above is taken from this great article, which you might want to read in full.
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.
Within my custom cell there are 2 span-elements.
<span class="FormElement">
<span class="customelement" id="code" name="code">BER01_CN_045_002</span>
</span>
Is there a way to avoid this?
See the demo, I am talking about cell "code".
I think, that you should don't spend your time in such kind of code optimization. Like I tried to explain in my previous answer the first <span> will be inserted by jqGrid for all form elements having the option edittype:'custom'. The second <span> you inserted yourself in the code of your custom formatter. It is permitted to have nested <span> elements like to have nested <div> elements. I recommend you better to follows the jqGrid standard code as trying to make any kind of optimization which nobody will see at the end except you.
Moreover if you look more in the HTML code of your page generated by jqGrid you will see that the form itself (the form with id="FrmGrid_grid" in your example) are placed inside of <span>. In the same way in the code of the column headers you will also find <span class="s-ico"> which has another two <span> elements as the children. Would you like to try to "optimize" also the code? So I repeat my advice just to hold jqGrid standards and not trying to optimize such small pieces of code like nested <span> elements.