HTML5 error messages - html

In my app I've got multiple tabs. In tabs I've got input fields and I want to validate these fields in client side. For this I try to use HTML5 attributes, for example required attribute or pattern attribute. In case when I've got empty field (field is required) in first tab which is selected, the error message appears The field is required, but when I've got empty field in other tab for example in third tab and my first tab is selected, the error message does not appears.
Question
Is there way to organize validation with HTML5 in this situation ?

Are you hiding form elements with display: none? If your elements are not visible they will not trigger the validation UI:
Report the problems with the constraints of at least one of the
elements given in unhandled invalid controls to the user. User agents
may focus one of those elements in the process, by running the
focusing steps for that element, and may change the scrolling position
of the document, or perform some other action that brings the element
to the user's attention. User agents may report more than one
constraint violation. User agents may coalesce related constraint
violation reports if appropriate (e.g. if multiple radio buttons in a
group are marked as required, only one error need be reported). If one
of the controls is not being rendered (e.g. it has the hidden
attribute set) then user agents may report a script error.
In this situation you will have to listen to the invalid event with your own script and perform a suitable action.

Related

Appmaker - How to enforce validation for suggest box when value is not selected from the options?

I have a form which contains a suggest box. When I click on submit one of the requirement is to not submit the form if the value is not selected from the options.
The problem occurs when we select a value and then clear it and then enter a text not chosen from the options. (Scenario quite possible as some users may not know that value is only to be chosen from the options etc)
In this case the value is still the old one and so the validation does not show any error thus creating an illusion for the user that the text which he entered is accepted as the value.
How do we restrict this?

Adding ASP.NET Server Side Controls Dynamically Like as Javascript

I have a simple aspx page.
In this page I want to add dynamically dropdownlist-textbox pairs that represent key-value pairs. But I dont know how much it is when page loading.
So I must add these controls to page dynamically(in runtime)
If I add these controls in codebehind 2 problems arise :
Page is reloaded in every appending because of autopostback. It couses blink.
Whenever page reloads, previous appending disappear.
If I add these controls in client-side(javascript) :
Controls cannot be reachable in codebehind(because no runat=server) so validation steps open to user(I think validation steps must operate in codebehind othervise this is an integrity problem).
What would be true approach about this problem ? Could give example ?
If you want to avoid the blink(page reload) you have to go for adding the control dynamically into your form using JavaScript.
Controls cannot be reachable in codebehind(because no runat=server)
This statement is not correct, you can always access your form control at server side using Request.Form collection. Check here for more details. You will be required to iterate over the contents of this collection to get the values.
I think validation steps must operate in codebehind othervise this is
an integrity problem
Validation you need to do by yourself before performing any operation. You might required to write some custom validation logic.

How to determine which livevalidations have failed when a form is submitted

I'm using LiveValidation in a tall form (so some of the form has scrolled off the top of the screen when the user clicks the submit button at the bottom of the form).
The user may not have visited every field on the form so may not have seen validation failures for "Presence" whilst filling in the form.
If the validation triggered by submitting the form fails, I'd like to determine which fields failed (so that I can set focus to the first field that failed validation so that it is visible to the user).
How can I determine which fields have failed validation? The answer is probably obvious, but it escapes me at the moment.

Using either GET or POST depending on submit button

I have a web application for tagging data and viewing data by tag, so my UI is a list of checkboxes for each tag, a list of checkboxes for each data item, a "Tag" button, which adds the checked tags to the checked data, and a "Filter" button, which ignores the checked data and just displays only the data items with the given tag.
My problem is that the former operation (tagging data) is "obviously" a POST operation, whereas the latter operation (viewing data according to a tag) is "obviously" a GET operation. But the method attribute is attached to the form, not the submit button, so I have to choose one or other for both buttons.
I don't want to make two forms, since as far as I can tell this would force me to duplicate the entire tag list. Is there any way I can choose my method based on the choice of submit button?
A JavaScript solution is permissible, but one without would be preferred.
(I am going to post an answer to this question, but I don't particularly like it, so I would welcome alternatives).
In principle, you could use the formmethod attribute in a submit button, as per HTML5. However, it is not recognized by IE, even in IE 9. The existence of the feature in HTML5 indirectly proves that previous versions of HTML lack a feature for this.
On the other hand, the POST method can be used even for simple viewing that does not cause any changes in the outside world, and in many situations it has to be used for technical reasons (e.g., too much data). So I think the method issue is not very relevant; just use POST.
I would honestly go with a javascript solution, in the onsubmit of the form fire a method which a) checks the submit button that was pressed and b) based on this changes the method of the form.
One possible solution would be to use POST, and then have the server give a 303 See Other header to change it into a GET request. This involves making two requests to serve the purpose of one, which is unfortunate, but at least means that the URL will change so people can link to a specific tag selection.
I agree with javascript solution, proposed by Jon Taylor, the problem is not if your form's method is GET or POST, but how do you filter/validate/sanitize user input. If your concern is related to the fact, that the user can manipulate the form's method, then you should implement solution to that matter on server side.

What is the attribute AlwaysEnableSilent used for?

I was looking at the raw HTML rendered by a SharePoint (2010) list item edit page, and I noticed that an input field (rich text field) made use of an AlwaysEnableSilent attribute. i have checked online for an explanation of what the attribute does, but have not been able to get a answer. Does anyone know what this attribute does?
Thanks, MagicAndi
ASP.Net validators allow you to turn them on/off using client side scripting using ValidatorEnable, but whenever you turn the validator on that way the validation fires immediately. Sometimes you (SharePoint) may want to be able to control which validators are active using client side scripting, but without the validation firing when you turn it on (during load, before the users have had the possiblity to fill out the fields).
In order to handle this SharePoint has defined its own function STSValidatorEnable with an extra parameter bSilent, so it can turn on validators without them firing.
They then found out that for some validators they always want them not to fire when STSValidatorEnable is called, even though the caller uses bSilent==false. So they introduced an attribute AlwaysEnableSilent which tells the validator never to fire when turned on using STSValidatorEnable, but only during postback.