remote: true form avoids js field validation

落爺英雄遲暮 提交于 2020-01-16 18:48:10
问题 This is my form: <%= form_for [@company,@company_branch], :html => { :onsubmit => "return validateName();" }, remote: true do |f| %> <%= f.text_field :name %> ... The "validateName" validation works fine when i don't use a remote call. But if do it remote, the form still gets submitted, even if my validation returns false. This is the .js for validation: function validateName() { var name = document.getElementById('name'); if( name.value == "" ) { highlightError(name, "Please provide a name")

jquery.validate lost on ajax replacement and only showing last error

青春壹個敷衍的年華 提交于 2020-01-05 07:10:29
问题 I am using jquery.validate in MVC 2 with MicrosoftMvcJQueryValidation. I have data annotations on my model which is then being translated into jquery validators. I am using a modification to MicrosoftMvcJQueryValidation as outlined by Soe Tun to allow my error messages to appear in a validation summary instead of beside the controls. When the page loads, everything works as expected. The problem is that I am using ajax forms with replace mode to rewrite the form. When I do this, I lose all of

returning a string with remote using the jquery validate plugin

浪尽此生 提交于 2020-01-04 03:59:29
问题 From the jquery documentation, describing the remote function of the jquery validate plugin: The response is evaluated as JSON and must be true for valid elements, and can be any false, undefined or null for invalid elements, using the default message; or a string, eg. "That name is already taken, try peter123 instead" to display as the error message. I have a php page that echo's a response, and it works as described if I use echo("true") or echo("false"). However, whenever I echo a string,

Catch Client Side Validation failure

混江龙づ霸主 提交于 2020-01-03 16:51:10
问题 I've got a form that I'm submitting based on a div click. I also have it launching a waiting indicator when clicked. I'm trying to find out if there is a way to detect if client side validation failed or not so that I can remove the waiting indicator/never show it after a submit attempt...or can I call the the client side validation manually before I attempt the submit? 回答1: you can try $('div').click(function() { if ($('form').valid()) { //form is valid else{ //invalid form } } }); 来源: https

SimpleForm+ClientSideValidations+bootstrap - Validation is not occuring on the form- all inputs are accepted

自闭症网瘾萝莉.ら 提交于 2020-01-01 09:26:07
问题 I am using the SimpleForm, ClientSideValidations, and ClientSideValidations-SimpleForm gems in a RoR application. I can render the form into the modal beautifully, however when the input loses focus no validation occurs and the form is submitted. Also note that I have tried using the fix found here: Segment of the view containing the form: <div class='modal hide' id=

Server side validation is done with data annotations instead of doing client side validation

前提是你 提交于 2019-12-24 17:28:18
问题 while I was working with validation in MVC, and I wrote a custom attribute to validate a property.Initially the client side validation was not working since attribute was not registered.When i clicked on the save button after contacting the server it was showing the error message.So can anyone tell how this server side validation took place instead of client side validation ? attribute usage -> [PhoneNumberHasPlus(ErrorMessage="Invalid number")] public string PhoneNumber {get;set;} attribute

Override client_side_validations behavior to validate hidden fields

拥有回忆 提交于 2019-12-24 07:37:03
问题 I am using the client_side_validations gem with Rails 3.1.0. I have been trying to use it to validate a hidden field that is set through a javascript widget. From what I have read on the gem's github page, the gem deliberately does not validate hidden fields because the user could not correct these fields. I have unsuccessfully tried to override this behavior. Is there a way to override this behavior for a particular field without modifying the client_side_validations code (other than the

ASP MVC 3: How can I do Client side Validation on a Select List?

两盒软妹~` 提交于 2019-12-24 03:30:36
问题 After reading a few question/answers here I have managed to work out how to add a Select list to a form and fill it with data, like so: @Html.DropDownList("S", new SelectList(ViewBag.S, "Id", "Nme"), "-- Sel a S --") And it works perfectly. However I would like to add some client-side Validation To validate whether the user has selected an option and not left it at the Default. I'm using the standard jquery stuff that comes with mvc 3, so presumably I have to do something with HTML

MV3 input validation - IE8 & IE9 behave differently

為{幸葍}努か 提交于 2019-12-21 06:25:47
问题 I'm using DataAnnotations to validate my input fields on a MVC3 application. I'm using regular expressions validations. I get the validation messages on the UI for IE8 & IE9. But I notice the difference when I hit the Save button even after the client side validation has failed. IE9 keeps me on the client side. On IE8 however, the control goes to the controller action, and I have to have a controller side TryValidateModel so that the validation errors out. Does anyone know why IE8 is doing a

Client-side validation for custom ValidationAttribute with AttributeTargets.Class

佐手、 提交于 2019-12-21 05:32:08
问题 Is it possible to implement client-site validation for custom ValidationAttribute, which is used in Class scope? For example my MaxLengthGlobal, which should assure global max limit for all input fields. [AttributeUsage(AttributeTargets.Class)] public class MaxLengthGlobalAttribute : ValidationAttribute, IClientValidatable { public int MaximumLength { get; private set; } public MaxLengthGlobalAttribute(int maximumLength) { this.MaximumLength = maximumLength; } public override bool IsValid