I'm racking my brain trying to figure this out...
I have an ASP.NET web form with some dynamically generated form fields. Depending on what value is chosen in a dropdown list, visibility is set on the following textbox. I do this with a client-side script.
The intent is a user selects "Other" from a dropdownlist, and the "Other Description" field appears next on the form. I'd like to add the ability to activate a requiredfield validator or some kind of validation on the "Other Description" textbox when the textbox is visible.
Any thoughts on how to accomplish this? In my testing postbacks weren't an option, since the form field needs to be on the page so an empty value is associated with it. (Not my choice - I inherited this code from another developer)
The most common approach would be to always render the validator, but render it as disabled and then enable it when desired.
Take a look at the documentation on ASP.NET validators, paying particular attention to the section labelled "Client-Side Validation" and, more specifically, the ValidatorEnable(val, enable) function.
ValidatorEnable(val, enable) Takes a client-validator and a Boolean
value. Enables or disables a client validator. Being disabled will
stop it from evaluating and it will always appear valid.
Note that the val parameter is the validator element, not a string ID.
Related
Can I know whether a field's(or a component's) value is 'null' or not in Oracle ADF.?
I have unchecked 'Mandatory' in EO.xml(It's required for us as per the application to un-check that option) and in JSF page (when I run the application) I'm clicking on 'Commit' without entering any text in all the fields, I thought like it should not allow me to Commit as I didn't entered any text. But it's getting Committed without saying any sort of error.
So, my question here is, can I stop it(Committing Without entering text in the fields), if anybody knows please help me..
And
Can I get out of this problem by using JavaScript.?
If the field is not set to be mandatory why should ADF stop you from getting empty data into that field?
You could add your own validator to the field to check if the value is empty instead - but that would basically be the same as turning mandatory on.
I have a custom web control which has two html select field and buttons i use them to make associated and available list box.But in few situations i have to Validate that Associated field must have at least 1 entity. I implemented a client side custom validator to confirm that. and its working great but issue is i am unable to fire Validate at the time List box is made empty it fires when i click save button and similarly when i have moved a few entries in associated List. validation Message is stile there and removes only when i click save button.
So i want to know how can i fire validator when i need using javascript...
To fire a validator from javascript we may use ValidatorValidate(document.getElementById('validator clientID'))
for more details see http://fczaja.blogspot.in/2009/07/aspnet-how-to-trigger-client-side.html
I have never noticed that ASP.NET automatically shuts down all subsequent postbacks until the field that validated as false is fixed by the user.
My scenario:
I have a form with 3 fields. One of them is a Textbox (txtCarName) with a required field validator and then I have a dropdown(ddlCarMake) with AutoPostBack=true, that filters and enables another dropdown (ddlCarModel) OnSelectedIndexChange.
Lets say the user clicks the save button without filling out the required textbox (txtCarName). They will be notifed that it is a required field.
Before they go and add a value to the required textbox lets say they decide to edit the ddlCarMake because they change their mind. In this case the filter does not happen since all subsequent postbacks are disabled. The user would be extremely confused.
How do ASP.NET developers avoid something like this from creating a poor user experience?
UPDATE:
After contacting Telerik they told me this is a known issue and is currently fixed in their internal build. The next release it will be fixed.
set the dropdownlist CausesValidation="False"
We have a required field on a page where the user has to select Gender which is a radio button with options Male and Female.
What we are finding is that there are cases when the entity has no gender stored in the database. There is javascript on the page
that does not allow user to leave the page without selecting a value. I am trying to figure out if there is a way to find out
continue without selecting a value. Would anyone be able to provide some insight as how it can be done ?
If I disable the javascript the page does not even submit. So there is another way that the user is able to skip a required field. Any ideas ?
Thanks in advance.
It's a good idea to have a back-end form validation check, as well as front-end. That way if users disable JavaScript, or find ways to bypass the front-end form validation check, the back-end will also check the form for errors.
Also, you can just set a default for the radio button, by adding the checked="checked" attribute to any of the radio button genders. This way the user will have a gender radio button already selected by default.
You may also add the <noscript></noscript> tags to your page to check if the user has JavaScript enabled. If the user does not have JavaScript enabled, your page can display a message that the user needs to enable Javascript to use your site.
More info here: http://www.w3schools.com/tags/tag_noscript.asp
It could be done using development tools (like the one we get by pressing F12 on Google Chrome) in modern browsers. As the validation is done through javascript, ie client side, a user can manipulate it from the browser.
I would like to change the order in which the fields in a form get checked.
The field Email should be checked before the field City. They are both obligatory.
I would also like that when the email address is invalid only one Popup is shown (by default I get two- one saying the email is invalid and one saying that the field cannot be null)
Is it possible to change the order of the checks and do the custom checks before the system ones?
Marco
The only supported method of changing the order in which the fields get checked, is changing the order on the form. I'm assuming that CRM just loops through it's collection of controls to perform the field validations. You could attempt to dive into the CRM javascript and figure out a method to hijack it.
A supported way of handling it would be to make the fields not required (either via javascript on the OnLoad, or updating the entity definition itself), and then on the OnSave, writing your own field validation. It's a lot of extra work, and you lose the little red asterisk showing the field is required, but you'd be able to evaluate them in the order you'd like (or display a single message with everything that's missing (why that isn't done by default in CRM I'll never know)), and be able to fix your email invalid / not null message.
CRM does not loop through its collection of controls as specified in the answer above.
The validation of the fields(business required) on a CRM form happen in the order in which they were added to the form, irrespective of where they are placed in the form. So, as of now, the only way to change the order in which they are validated is to add them in the same order as you want them validated.
So far.. I believe the only option to work around this is stated in this link.
http://social.microsoft.com/Forums/en-US/8f402463-23aa-4bc1-862b-4f4093a0cce8/required-fields-order-of-validation?forum=crmdevelopment
Basically you would need to use javascript. Have only one field as mandatory. On change of this field set the next field (in the correct order) to mandatory and so on.. hectic but only way.