customvalidator

Where should Rails 3 custom validators be stored?

旧巷老猫 提交于 2020-01-19 04:42:58
问题 I've seen docs/websites show that custom validators should go in a /lib or /lib/validators directory of a project. I've found (by reading an answer to another post) that they only seem to work in config/initializers . Does anyone know, or have a pointer to official documentation that shows where custom validators should live? 回答1: If you place your custom validators in app/validators they will be automatically loaded without needing to alter your config/application.rb file. 回答2: If you add

Validation not working when adding query string

拜拜、爱过 提交于 2020-01-15 02:38:39
问题 My validations are not working when redirecting from one page to another on passing query string as a parameter with response.redirect or with windows.location.href . When I am redirecting from one page to another page with this: <asp:Button ID="New" runat="server" Text="New" OnClientClick="Transfer()" /> function Transfer() { window.location.href = "Abc.aspx?flag=yes"; //when adding query string my validation doesnt work //window.location.href = "Abc.aspx";// When removing query string my

Get error message when using custom validation attribute

自闭症网瘾萝莉.ら 提交于 2020-01-01 05:41:12
问题 I'm using the CustomValidationAttribute like this [CustomValidation(typeof(MyValidator),"Validate",ErrorMessage = "Foo")] And my validator contains this code public class MyValidator { public static ValidationResult Validate(TestProperty testProperty, ValidationContext validationContext) { if (string.IsNullOrEmpty(testProperty.Name)) { return new ValidationResult(""); <-- how can I get the error message from the custom validation attribute? } return ValidationResult.Success; } } So how can I

CustomValidator textbox required on radiobuttonlist select

只愿长相守 提交于 2019-12-24 14:11:53
问题 On my page I have a Radio button list and a textbox. The textbox is hidden by default then appears if the user clicks yes. Once they click yes then the textbox must be filled in before they can proceed. I've put in the following code, however it doesn't seem to work at all and when the button is pressed to go to the next page it continues instead of stopping and asking the user to enter something in the box. function Q12iYes() { document.getElementById('txt12i').style.display = "block" }

control names in a custom validator .NET Client Side Validation

◇◆丶佛笑我妖孽 提交于 2019-12-23 05:12:44
问题 I have a gridview with three columns of textboxes. It can have as many rows as necessary but its usually only about 5 rows. Each row needs to be validated. I want to create a client side validator that sums 2 of the columns together and compares it with the third column to check that the user has entered the data correctly. Just in case you are wondering, it's part of the spec that the operator must enter the third column rather than simply summing the two previous columns together in the

ASP.NET Custom Validator and AJAX

孤街浪徒 提交于 2019-12-23 04:42:01
问题 I implemented a Custom Validator with AJAX, and It works fine: EDITED . Add ASPX code <asp:DetailsView ID="DetailsView" runat="server" Height="50px" Width="25em" DataSourceID="SqlDataSource1" AutoGenerateRows="False" DefaultMode="Insert" CellPadding="4" ForeColor="#333333" GridLines="None" OnItemInserting="DetailsView_ItemInserting"> <Fields> <asp:TemplateField HeaderText="Nombre *"> <InsertItemTemplate> <asp:TextBox ID="txtNombre" runat="server" Text='<%# Bind("nombre) %>'></asp:TextBox>

Model validation on update in django

孤者浪人 提交于 2019-12-22 10:53:22
问题 I've created a model called Term and a validator for it, like this: from django.db import models from django.contrib.auth.models import User from django.core.exceptions import ValidationError def validate_insensitive_exist(value): exists = Term.objects.filter(word__iexact = value.lower()).exists() if exists == True: raise ValidationError("This term already exist.") class Term(models.Model): word = models.CharField(max_length=200, unique=True, validators=[validate_insensitive_exist]) related

CakePHP 2.1 - Custom Validation Rule - Check for Unique Field Value Combination

自作多情 提交于 2019-12-22 10:45:05
问题 I have a couple of columns (ip, provider_id) for which I want combinations of values to always be unique. Therefore, I am trying to build a custom validation function. But I am having issues grabbing on the value of the secondary field. This is my code so far in the model: public $validate = array( 'ip' => array( 'rule' => array('uniqueClick', 'provider_id'), 'message' => 'The click is not unique.' ) ); public function uniqueClick ($ip, $field) { $count = $this->find('count', array(

Custom validator fires but does not prevent postback

冷暖自知 提交于 2019-12-22 05:48:16
问题 I've seen a lot of questions about this already, but I'm stumped! Please help! I have a customvalidator. It's firing but it's not preventing postback. Please help me in doing so! I can see that console.log registers before the post. But, it posts back anyway. How do I prevent the postback? I've tried adding a control to validate, and validate empty text equal to true. I also tried adding e.preventdefault, which did not work :( How can I prevent the postback? <script type="text/javascript"> //

Enable/disable RequiredValidator on client-side / CustomValidator not firing

a 夏天 提交于 2019-12-22 05:06:32
问题 I've got a drop-down where the user selects a Country. It is a required "field". Next to it, there is a textfield named State. If the user selects US, then the field State is required. If the user selects e.g. Sweden, the State is not required, since Sweden has no states. Example code: <asp:DropDownList runat="server" ID="Country"></asp:DropDownList> <asp:RequiredFieldValidator ControlToValidate="Country" runat="server" Display="Static" ErrorMessage="Required field" /> <asp:TextBox runat=