MVC unobtrusive general message - asp.net-mvc-4

Im working in a project where the validations messages with unobtrusive system works fine.
When any attribute is uncompleted or wrong the proper error messages appear, at client side ofc.
The problem is the following. I need to set an general error message at the top of the site (besides to each field validation message error). I know i can use #Html.ValidationSummary but i dont want the list of fields, what i need is one general message telling the user that there is something wrong with the form.
Regards.
Edit: On jquery before submit i'm doing $("#frmSubmit").valid();

Did you try using the ValidationSummary(bool) overload? Supplying true excludes property errors.

Why not just have check ModelState on your view like this:
#if (!ViewContext.ViewData.ModelState.IsValid)
{
<div>Your error message here...</div>
}
Then style your div to be errorish...

Related

What is the proper way to test mandatory field in selenium

I am testing my web application using Selenium. All the form validation in the web application is done by HTML5 and some JS(for safari browser). I want to know what is the proper way to test the form validation.
Currently I am using one approach, i.e Before I filled up a mandatory field I clicked on the submit button. If the page is not refreshed then I assume the form validation working correctly. But I think there should be a better approach to do it. I am unable to find any proper solution. Any suggestion will be highly appreciated.
I also go through this link. But it is not working for me because it is not enough to have required attribute (eg required attribute does not work in older Safari browser).
Rather than checking if the page is refreshed or not, you should instead expect that it is not and that a certain error message or field highlighting or something is applied to the current page. When in an error state, the input fields probably get given an extra class, or an error div/span might be added to the DOM, try checking for that sort of thing

Display error on actionProductUpdate hook execution

Is there any way to display an error message after actionProductUpdate hook is executed in a module?
Looking at the Prestashop code, the hook is triggered in AdminProductController, but the return value is not being processed. Also adding any message in passed Product object seems to be out of my requirement.
The purpose is to provide user with an error message in case of wrong input, database update error etc after clicking on Save button in back-office product edit page.
in belvg blog user Prestarocket post the the very helpful comment:
"Why not using hookActionProductSave ?
With this hook, you can add errors to the controller ($this->context->controller->errors[])"
Regards

In richfaces form based error message possible?

I would like a catch-all display of any errors or exceptions. For instance I would like to catch 500 responses to AJAX requests and display the summary in a text field. More so I would like a single message area for the entire form (w/o specifying a separate message tag for every input or button). How can this be implemented using richfaces?
I've read the documentation located at the richfaces demo site, but the 500 responses still get through.
For displaying all validation errors in your form in a single location use the <rich:messages/> component instead of the <rich:message> as shown in: http://livedemo.exadel.com/richfaces-demo/richfaces/messages.jsf
As I look around I think my paradigm is wrong. I was thinking I would catch an HTML error code on return, but it looks like richfaces catches it server side and turns it into a page to display the details on the front end. I'll look into how to set up faces-config to redirect to one of my classes or maybe just create an attribute in the bean that I set to the message in a catch block.

MonoRail - Server-side vs. Client-side Form Validation

I'm using MonoRail and was wondering how it decides when to use client-side vs. server-side validation? In my model class I have [ValidateNonEmpty] on two properties, one is a textbox, the other is a dropdown. The textbox triggers client-side validation on form submission, if I leave the dropdown empty though it posts back to the server and returns back the validation error from server-side. Is there a way to get the dropdown to trigger client-side validation? Also it's odd because after the postback, it clears what I had entered in the dropdown but maintains the state of the textbox (viewstate anyone??)
Thanks,
Justin
It viewed source and I saw that it was using jQuery for the client-side validation. It had:
"business.businesstype.id":{ required: "This is a required field" },
for the dropdown, which wasn't working. I noticed that it was using 0 as the default dropdown value so I manually put in firstoptionvalue and that got it working:
$FormHelper.Select("business.businesstype.parent.id", $businessTypes, "%{value='id', text='name', firstoption='Select a Business Type', firstoptionvalue=''}")

Z_Form :: Adding a custom error message to zend_form inside Action Controller

I'm new to ZF and I'm discovering how to use Zend_Form and utilize it's capability like validating and filtering input values. I already know the basic of Zend_form like building a form and add element into it. My problem is that I want to add a custom error message to form element and I want to define that message inside the action controller that instantiated the form. I want to defined the error message inside the controller because I need to perform a validation against the database. For example checking if the username/email already exist in the database. I tried googling and that's leads me to setErrorMessage method of zend_form but when I try to use it, the error message is not showing at all... I also tried zend_form->setError and still no error displaying in the view script. Is my idea of setting custom error in the action controller correct or this should be done the other way?
Are you using Zend_Validate_Db_RecordExists?
Something like this should work:
$form->getElement('username')->getValidator("RecordExists")->setMessage('This username exists',
Zend_Validate_Db_RecordExists::ERROR_RECORD_FOUND
);
This works for me:
$form->getElement('username')->addError('This username exists.');