How to override symfony2 hover message in form? - symfony

I've create a symfony2 form, and I want to override the hover message (when you put your mouse on the input). There is a message like this "Please fill out this field".
Any idea?

this is HTML5 validation
check the documentation: http://symfony.com/doc/current/book/forms.html#book-forms-html5-validation-disable
The client-side validation, however, can be disabled by adding the novalidate attribute to the form tag or formnovalidate to the submit tag.

Related

How can I make the HTML5 input required attribute behave with .NET?

I am using ASP.NET 4.
My UI depends on using an update panel. Updating certain UI elements requires a PostBack which is handled by the ScripManager. Basic stuff. These action occur before the fields are submitted.
The problem comes in with the HTML5 markup that have to deal with.
<input type="text" id="foo" aria-required="true" required>
Using a .NET TextBox control and adding attributes, I get rendered code as such:
<input name="foo" type="text" id="foo" aria-required="true" required="required" />
The HTML5 behavior is that each time a PostBack occurs, the input field thinks it should alert the user, since no value is present in the field, even though the user if off doing other actions within the UI.
Is there a way to bring this HTML5 behavior under control, such that the the INPUT field ignores PostBack?
ASP.NET web forms is a bit strange in that the entire page is a "form" and that postbacks occur in order to fire server side events, not simply to submit form data. As the form "submit" event is being fired, the HTML form validation API will attempt to validate the entire contents of the form. In this case you are firing a submit event that isn't actually a form submission - so the validation behaviour is incorrect.
There are a few ways you could deal with this.
You could add the "formnovalidate" attribute to all the buttons and input with type submit elements that trigger a postback but do not actually submit the form. It is possible to alter this with JavaScript using the inputElement.formNoValidate property as well as using jQuery and JavaScript attribute methods.
You could add the "novalidate" attribute to the form element to avoid client side validation altogether, whilst having the semantic meaning behind the attribute on the input elements involved - perhaps using something like jQuery validation to validate the form yourself on submission, or use the validityState API to perform totally custom validation in JavaScript.
You could conditionally add and remove the "required" attribute, and change the value of "aria-required" using jQuery or native JavaScript so that these are only present during the form submission phase of the process.
You could conditionally add and remove the "novalidate" attribute to the form element, or set the formElement.noValidate property in order to determine if client side validation occurs.

ASP.NET validation summary doesn't show validator

I have a new validator added to one screen to validate a text box. If user clicks on submit button, the validation summary will pop up but not showing the text of this validator. It works well with all other validators on this page.
In other words, this validator works but is not shown in the validation summary.
Check if you use the same name as the default validation group may not verification. I suggest you to check out her hard have added value.
I figured it out, I used the Text property of the validator instead of ErrorMessage property. Thanks for your comment #MichaelLiu which made me look at the code.

aria-labelledby attribute and asp.net validators

I'm creating an html5 site in VS2010 using .net 4.0 and the stock validators. To make the validators accessible I've added an aria-labelledby to the associated textbox and set the validators id in the aria-labelledby value. The validators have their id mode set to static. Validation labels are hidden by display:none css styling, which is removed when triggered.
Seems to work fine, as NVDA sees the error message and is associating it to the proper text box. But when I go to validate it I get the following error:
aria-labelledby attribute must point to an element in the same document
So, the question is ... can the aria-labelledby reference a control that is not visible?
Quick answer is yes ... after some more testing I found out that NVDA will read the hidden span tag that is the validator error text.
The issue I was having was in making a required validator have its error message receivable by NVDA. Unfortunately the error is shown after the IsValid function is fired ... making the event fire after a postback. NVDA would see the page with the error messages, but not know that they were new.
To fix it I'm firing the validator on the blur event, as shown below.
I added a blur event to the control being validated, and called the validator attached to that control
onblur="validateControl(RequiredFieldValidatorID)"
The function called uses the ValidatorValidate function.
function validateControl(n) {
ValidatorValidate(n);
}
This makes a required validator fire on blur. Still need to refocus on the control that has an error, but I think I'll need to catch the tab and redirect ... work in progress.

Highlight only required field validation errors

In one of our projects we want to show the "Required field validation error" by changing the border color of the corresponding textbox. our page contains a lot of required field validator,regular expression validator etc. But we want to highlight only the required field errors.
Is there any way to do this without using any custom validation function.?
or Is there any method to find all the required field validators in a page in the client side. If we can find this i think we can highlight the corresponding error textbox
one option, maybe less annoying than switching to custom validators, is to create your own javascript validation function that is triggered with a submit click. from here you can change the appearance of the invalid fields.

Does the Jquery validation plugin require a form tag?

I want to validate some asp.net textboxes with the jQuery Validation plugin found at
http://docs.jquery.com/Plugins/Validation, but it appears that the elements must be between a form tag. If I have just a couple elements, I would hardly call that a form, so I would rather not have them wrapped inside a form element. Is there a way around this? Also, if I have two buttons on the form, a cancel and a submit button and I want the form only to validate when the submit button is clicked, but not the cancel button, how is this accomplished?
I have just a couple elements, I would
hardly call that a form, so I would
rather not have them wrapped inside a
form element.
If the elements are not within a form tag, then it is not a valid HTML document, so behavior within script might get wonky depending on how the browser deals with the malformed HTML.
Most browsers will create a form implicitly, but now you have no control over the form's behavior. The defaults are usually be a post action form targeted at the requested page's URL.
The problem is, you probably have no idea what selector to use in the JQuery to get a reference to the form... but I suppose $("form") would do the trick.
validate when the submit button is clicked, but not the cancel button
The plug-in intercepts and runs on the submit event of a form. Generally cancel buttons are html input elements with the type attribute set to "reset":
<input type="reset" value="cancel" />
A reset type button will not cause the form to submit, and this will not trigger the validation.
If you use another button type, make sure the onclick even returns false. This cancels the form's submit action but still allows you to run javasctipt of your own when the button is clicked.
The jquery validate plugin requires a form element to function, so you should have your form fields (no matter how few) contained inside a form.
You can tell the validation plugin not to operate on form submission, then manually validate the form when the correct submit button is clicked.
For example, using a class to identify the correct submit button:
$(document).ready(function() {
var form = $("form");
form.validate({
onsubmit: false,
});
//Validate form only if validation submit button is clicked
//Allows cancel submit buttons to function properly
$('.validate', form).click(function() {
if (form.valid()) {
form.submit();
}
else {
form.validate().form();
}
});
});

Resources