[jQuery] Re: validation plugin: how to add custom messages for groups
Sorry, the third validator must only get "activated" if both are empty (in other words, it must return true if either is not empty): function validateNameInputs(value, element) { return firstNameInput.value || lastNameInput.value; } On Jan 30, 11:19 am, Mihai Danila wrote: > There was a small typo in validateLastNameInput. Here's the corrected > code. > > > > jQuery.validator.addMethod('first-name-input', validateFirstNameInput, > 'First name is missing.'); > jQuery.validator.addMethod('last-name-input', validateLastNameInput, > 'Last name is missing.'); > jQuery.validator.addMethod('name-input', validateNameInputs, 'First > and Last name are missing.'); > var firstNameInput = document.getElementById('firstNameInput'); > var lastNameInput = document.getElementById('lastNameInput'); > function validateFirstNameInput(value, element) { return ! > lastNameInput.value || value; } // 1 > function validateLastNameInput(value, element) { return ! > firstNameInput.value || value; } // 2 > function validateNameInputs(value, element) { return > firstNameInput.value && lastNameInput.value; } // 3 > > On Jan 30, 11:18 am, Mihai Danila wrote: > > > I think you can put three validators on the fields, with > > jQuery.validator.addMethod. I don't know if you can add multiple > > validators for the same CSS class, so I'm putting extra CSS classes on > > the inputs: > > > > > > > jQuery.validator.addMethod('first-name-input', validateFirstNameInput, > > 'First name is missing.'); > > jQuery.validator.addMethod('last-name-input', validateLastNameInput, > > 'Last name is missing.'); > > jQuery.validator.addMethod('name-input', validateNameInputs, 'First > > and Last name are missing.'); > > > var firstNameInput = document.getElementById('firstNameInput'); > > var lastNameInput = document.getElementById('lastNameInput'); > > function validateFirstNameInput(value, element) { return ! > > lastNameInput.value || value; } // 1 > > function validateLastNameInput(value, element) { return > > firstNameInput.value || value; } // 2 > > function validateNameInputs(value, element) { return > > firstNameInput.value && lastNameInput.value; } // 3 > > > Validator #1 will always run for the first name input, but will choose > > to never display a message as long as the last name input is empty. If > > the last name input is not empty, then this validator will actually > > check the given value (the value of the first name input) and validate > > accordingly. > > > Validator #2 is in a similar situation. > > > Validator #3 will display an error only if both are empty. > > > Think of them as working together to only activate the errors when > > only a subset of the possible conditions get applied. > > > I'm looking for a way to do this with a single validator myself. I > > have dynamic forms and more complex situations, so I can't employ this > > solution. If anyone knows how to do it, please don't hesitate to put > > it in. > > > Mihai > > > On Jan 5, 4:26 pm, claudes wrote: > > > > i have a group that contains both first and last name. i'm wondering if > > > it is > > > possible to have custom messages for groups. i'm trying to achieve > > > something > > > to the following: > > > > a. if both first and last name are not filled in: First and Last name are > > > Required > > > b. if only first is filled in: last name is required > > > c. if only last is filled in: first name is required > > > > is this possible? > > > -- > > > View this message in > > > context:http://www.nabble.com/validation-plugin%3A-how-to-add-custom-messages... > > > Sent from the jQuery General Discussion mailing list archive at > > > Nabble.com.
[jQuery] Re: validation plugin: how to add custom messages for groups
There was a small typo in validateLastNameInput. Here's the corrected code. jQuery.validator.addMethod('first-name-input', validateFirstNameInput, 'First name is missing.'); jQuery.validator.addMethod('last-name-input', validateLastNameInput, 'Last name is missing.'); jQuery.validator.addMethod('name-input', validateNameInputs, 'First and Last name are missing.'); var firstNameInput = document.getElementById('firstNameInput'); var lastNameInput = document.getElementById('lastNameInput'); function validateFirstNameInput(value, element) { return ! lastNameInput.value || value; } // 1 function validateLastNameInput(value, element) { return ! firstNameInput.value || value; }// 2 function validateNameInputs(value, element) { return firstNameInput.value && lastNameInput.value; } // 3 On Jan 30, 11:18 am, Mihai Danila wrote: > I think you can put three validators on the fields, with > jQuery.validator.addMethod. I don't know if you can add multiple > validators for the same CSS class, so I'm putting extra CSS classes on > the inputs: > > > > jQuery.validator.addMethod('first-name-input', validateFirstNameInput, > 'First name is missing.'); > jQuery.validator.addMethod('last-name-input', validateLastNameInput, > 'Last name is missing.'); > jQuery.validator.addMethod('name-input', validateNameInputs, 'First > and Last name are missing.'); > > var firstNameInput = document.getElementById('firstNameInput'); > var lastNameInput = document.getElementById('lastNameInput'); > function validateFirstNameInput(value, element) { return ! > lastNameInput.value || value; } // 1 > function validateLastNameInput(value, element) { return > firstNameInput.value || value; } // 2 > function validateNameInputs(value, element) { return > firstNameInput.value && lastNameInput.value; } // 3 > > Validator #1 will always run for the first name input, but will choose > to never display a message as long as the last name input is empty. If > the last name input is not empty, then this validator will actually > check the given value (the value of the first name input) and validate > accordingly. > > Validator #2 is in a similar situation. > > Validator #3 will display an error only if both are empty. > > Think of them as working together to only activate the errors when > only a subset of the possible conditions get applied. > > I'm looking for a way to do this with a single validator myself. I > have dynamic forms and more complex situations, so I can't employ this > solution. If anyone knows how to do it, please don't hesitate to put > it in. > > Mihai > > On Jan 5, 4:26 pm, claudes wrote: > > > i have a group that contains both first and last name. i'm wondering if it > > is > > possible to have custom messages for groups. i'm trying to achieve something > > to the following: > > > a. if both first and last name are not filled in: First and Last name are > > Required > > b. if only first is filled in: last name is required > > c. if only last is filled in: first name is required > > > is this possible? > > -- > > View this message in > > context:http://www.nabble.com/validation-plugin%3A-how-to-add-custom-messages... > > Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: validation plugin: how to add custom messages for groups
I think you can put three validators on the fields, with jQuery.validator.addMethod. I don't know if you can add multiple validators for the same CSS class, so I'm putting extra CSS classes on the inputs: jQuery.validator.addMethod('first-name-input', validateFirstNameInput, 'First name is missing.'); jQuery.validator.addMethod('last-name-input', validateLastNameInput, 'Last name is missing.'); jQuery.validator.addMethod('name-input', validateNameInputs, 'First and Last name are missing.'); var firstNameInput = document.getElementById('firstNameInput'); var lastNameInput = document.getElementById('lastNameInput'); function validateFirstNameInput(value, element) { return ! lastNameInput.value || value; } // 1 function validateLastNameInput(value, element) { return firstNameInput.value || value; }// 2 function validateNameInputs(value, element) { return firstNameInput.value && lastNameInput.value; } // 3 Validator #1 will always run for the first name input, but will choose to never display a message as long as the last name input is empty. If the last name input is not empty, then this validator will actually check the given value (the value of the first name input) and validate accordingly. Validator #2 is in a similar situation. Validator #3 will display an error only if both are empty. Think of them as working together to only activate the errors when only a subset of the possible conditions get applied. I'm looking for a way to do this with a single validator myself. I have dynamic forms and more complex situations, so I can't employ this solution. If anyone knows how to do it, please don't hesitate to put it in. Mihai On Jan 5, 4:26 pm, claudes wrote: > i have a group that contains both first and last name. i'm wondering if it is > possible to have custom messages for groups. i'm trying to achieve something > to the following: > > a. if both first and last name are not filled in: First and Last name are > Required > b. if only first is filled in: last name is required > c. if only last is filled in: first name is required > > is this possible? > -- > View this message in > context:http://www.nabble.com/validation-plugin%3A-how-to-add-custom-messages... > Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: [validate] Group Validation, Validation Events
Nice; I'll get to using that. I guess all that's missing is a way to register an onAfterCheck type event handler. :) On Dec 8, 1:58 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]> wrote: > Thanks for the feedback. I agree that post-validation events make more > sense. The seperation of validation and message display is partially > in place - you can already use the showErrors-option to fully override > the message display. > > In the meantime, here's a workaround: > > var validator = $(...).validate(); > var check = validator.check; > validator.check = function(element) { > var result = check.apply(this, arguments); > // do something after validating an element, use element and result > variables > return result; > > }); > > Jörn > > On Mon, Dec 8, 2008 at 7:20 PM, Mihai Danila <[EMAIL PROTECTED]> wrote: > > > If the new handlers would want to extend on (be siblings of) the > > "invalidHandler" feature, then they should be consistent with > > invalidHandler's behavior. If invalidHandler fires after validation, > > then that's when the new events should fire. > > > On a slightly different note, a passive observer may not care when the > > event fires relative to the validation itself, namely because a > > passive observer cares if the field "would be considered valid" and > > not much about what's out there. For observers that intend to make > > changes, like the one that sets up tooltips, a post validation event > > makes it easier, as all the markup and data is there to manipulate > > when the post-validation event fires. A pre-validation event would > > achieve this reasonably only if it allowed the handler to specify a > > callback that generates the label, or other such complications. (Note > > Windows programming has historically provided both pre- and post- > > events for various processes---recall OnBeforeSave and OnAfterSave--- > > but that may also be too much.) > > > In general, the more hooks one provides, the better the performance > > that can be achieved with the framework; our point in case, the > > tooltip example, indicates that an after- event handler will do work > > that makes the label generation process superfluous (hence unnecessary > > work on the part of the validator). > > > I would go ahead and provide the after- event. I'm thinking in the > > future you'll want to separate the validation from the rendering of > > the vaidation results and that will make it easier to allow > > customizations of the rendering (I think there's a note about this > > separation on your site) but hey, I've only just arrived in both > > jQuery and Validator workd; you'll get better input on this hot topic > > from more informed users. > > > Mihai > > > On Dec 8, 11:47 am, "Jörn Zaefferer" <[EMAIL PROTECTED]> > > wrote: > >> Currently those field-based validation events are missing. Would you > >> need an event that is called whenever a field is validated? Before > >> validation occurs? After it's done? Only when (in)valid? > > >> There are quite a few potential permutations, I'd like to focus on > >> those being actually useful. > > >> Jörn > > >> On Mon, Dec 8, 2008 at 4:42 PM, Mihai Danila <[EMAIL PROTECTED]> wrote: > > >> > I have a few questions, given that I'm new to the validation plugin. > > >> > 1. We validate groups of controls; validation for the entire group > >> > succeeds if at least one field is present -- call it REQUIRED on > >> > steroids. To implement this, we use one call to addMethod + one CSS > >> > class per group of controls. (Is there a better way?) Now assume I > >> > submit a form containing one such group with three fields, all blank. > >> > I get three validation messages, one next to each field. So far so > >> > good. Now assume I enter a value in one of the fields and blur it. How > >> > can I cause all the remaining fields to validate and have their > >> > messages disappear? > > >> > I can cause the fields within a group to validate by placing blur > >> > events and triggering validate for the entire group of fields. But > >> > this is costly; what I'm really looking for here is an event from the > >> > validator that triggers whenever some part of the form is being > >> > validated. That would be more natural. Is there such an event? > > >> > 2. I'm trying to put the validation messages in tooltips. Again, I > >> > miss this validation event to let me scan the form and create the > >> > tooltips. > > >> > Is there such a validation event or is it on the TODO list? (Note: The > >> > invalidHandler function only executes when I try to submit the form, > >> > not when a control is validated; as such, it doesn't fit the bill.)
[jQuery] Re: [validate] Group Validation, Validation Events
If the new handlers would want to extend on (be siblings of) the "invalidHandler" feature, then they should be consistent with invalidHandler's behavior. If invalidHandler fires after validation, then that's when the new events should fire. On a slightly different note, a passive observer may not care when the event fires relative to the validation itself, namely because a passive observer cares if the field "would be considered valid" and not much about what's out there. For observers that intend to make changes, like the one that sets up tooltips, a post validation event makes it easier, as all the markup and data is there to manipulate when the post-validation event fires. A pre-validation event would achieve this reasonably only if it allowed the handler to specify a callback that generates the label, or other such complications. (Note Windows programming has historically provided both pre- and post- events for various processes---recall OnBeforeSave and OnAfterSave--- but that may also be too much.) In general, the more hooks one provides, the better the performance that can be achieved with the framework; our point in case, the tooltip example, indicates that an after- event handler will do work that makes the label generation process superfluous (hence unnecessary work on the part of the validator). I would go ahead and provide the after- event. I'm thinking in the future you'll want to separate the validation from the rendering of the vaidation results and that will make it easier to allow customizations of the rendering (I think there's a note about this separation on your site) but hey, I've only just arrived in both jQuery and Validator workd; you'll get better input on this hot topic from more informed users. Mihai On Dec 8, 11:47 am, "Jörn Zaefferer" <[EMAIL PROTECTED]> wrote: > Currently those field-based validation events are missing. Would you > need an event that is called whenever a field is validated? Before > validation occurs? After it's done? Only when (in)valid? > > There are quite a few potential permutations, I'd like to focus on > those being actually useful. > > Jörn > > On Mon, Dec 8, 2008 at 4:42 PM, Mihai Danila <[EMAIL PROTECTED]> wrote: > > > I have a few questions, given that I'm new to the validation plugin. > > > 1. We validate groups of controls; validation for the entire group > > succeeds if at least one field is present -- call it REQUIRED on > > steroids. To implement this, we use one call to addMethod + one CSS > > class per group of controls. (Is there a better way?) Now assume I > > submit a form containing one such group with three fields, all blank. > > I get three validation messages, one next to each field. So far so > > good. Now assume I enter a value in one of the fields and blur it. How > > can I cause all the remaining fields to validate and have their > > messages disappear? > > > I can cause the fields within a group to validate by placing blur > > events and triggering validate for the entire group of fields. But > > this is costly; what I'm really looking for here is an event from the > > validator that triggers whenever some part of the form is being > > validated. That would be more natural. Is there such an event? > > > 2. I'm trying to put the validation messages in tooltips. Again, I > > miss this validation event to let me scan the form and create the > > tooltips. > > > Is there such a validation event or is it on the TODO list? (Note: The > > invalidHandler function only executes when I try to submit the form, > > not when a control is validated; as such, it doesn't fit the bill.)
[jQuery] [validate] Group Validation, Validation Events
I have a few questions, given that I'm new to the validation plugin. 1. We validate groups of controls; validation for the entire group succeeds if at least one field is present -- call it REQUIRED on steroids. To implement this, we use one call to addMethod + one CSS class per group of controls. (Is there a better way?) Now assume I submit a form containing one such group with three fields, all blank. I get three validation messages, one next to each field. So far so good. Now assume I enter a value in one of the fields and blur it. How can I cause all the remaining fields to validate and have their messages disappear? I can cause the fields within a group to validate by placing blur events and triggering validate for the entire group of fields. But this is costly; what I'm really looking for here is an event from the validator that triggers whenever some part of the form is being validated. That would be more natural. Is there such an event? 2. I'm trying to put the validation messages in tooltips. Again, I miss this validation event to let me scan the form and create the tooltips. Is there such a validation event or is it on the TODO list? (Note: The invalidHandler function only executes when I try to submit the form, not when a control is validated; as such, it doesn't fit the bill.)
[jQuery] Re: How to display validation error messages in a tooltip? JORN
Did anything get done in this direction? In some cases, putting the error messages inline is unreasonable. An error container is also unreasonable, for it requires scrolling to the container and adding links to the fields from each error message to make its function decent. Is there a post-validation event? At least I could scan for error labels and create tooltips each time the validity changes. Mihai On Nov 2, 4:51 am, Kenet <[EMAIL PROTECTED]> wrote: > Jorn, > > Back in April of 2007 you had a discussion on your comments section > for your ToolTip Plugin, here's a quote of that conversation. > > > OSCAR 24. April 2007 |10:55 Add tooltip to validation. > It is posible to add a tooltip in order toshow the “error message” of > a validation. > > My Problem: > I have a form very big for that reason I only can put a “*” if a > input > validation fails. I would like to add a tooltip with the info about > the error. > > I don’t know if I could integrate your tooltip & validation plugins. > > Thanks in advanced. > > Jörn 24. April 2007 |17:27 @Oscar: Provide the showErrors option. > Put > only the star beneath the field and the error message inside the > title > attribute of the input. Modify the tooltip plugin: The check if an > element has a title attribute has to be done when the tooltip is > displayed, not when applying the plugin. > > I’ll try to provide an example with the necessary tooltip > modifications, but it may take a while. > > OSCAR 24. April 2007 |18:16 Great!!! I will try to do it. > > OSCAR 25. April 2007 |09:34 Maybe could be nice to provide tootip > message optin into validation with a new param: > > rules > messages > TOOTIPS > > Ii will be nice in order to mantain separatlly view & controller, if > we put tooltip text into the title we are mixing view & controller. > It > is hçjust an idea! > > Jörn 25. April 2007 |18:46 @Oscar: Adding a tooltip option to > validation is an interesting approach, I’ll check that. > I don’t see an issue with putting messages into the title attribute. > > > My question is, did you ever get in further with that idea? I would > like to display my error messages in a tooltip as well. Please let me > know. > > Thanks, > Ken
[jQuery] [validate] Rule Selectors
Hi, Is it possible to use jQuery selectors to identify the elements to which certain rules should apply? If this feature exists, then I won't have to unnecessarily complicate the component that dynamically creates my form and that features various control types. Thanks, Mihai
[jQuery] [validate] Required on Fields Matching Criteria
Hi guys, Is it possible for the validator component to make exactly one field within a chosen set required? If either input has a value, then validation succeeds. If neither input has a value, then both fields should be marked as failed with preferably a message next to them. Thanks, Mihai