[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-13 Thread Sam

>>How to change the default position of an error message in Jquey form 
>>validation plugin?

This is easy to do. Just create a label element where you want the
error message to appear. If the field you are validating is called
"foo" your label would look like:

This field is required

You must put class="error" or if you have overridden the default error
class name you should set it to whatever you changed it too. You also
need to have the error message in the label as validate will now
ignore whatever is defined in the messages config (i think??).

You can put that label anywhere on the page... probably still has to
be inside the form.


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread Don Dunbar
Hi, glad you found a solution:to  prevent the user from filling out both
inputs in the first place.
[code]$("#days").change(function(){

  $("#participations").attr("disabled","disabled");
});
 $("#participations").change(function(){
$("#days").attr("disabled","disabled");
   });
[\code]
DED

On Mon, Oct 12, 2009 at 3:55 AM, Phper  wrote:

>
> Also, how to prevent a user filling out both fields?
>
> On Oct 12, 4:48 pm, Phper  wrote:
> > How to change the default position of an error message in Jquey form
> > validation plugin?
> >
> > On Oct 12, 4:33 pm, Gordon  wrote:
> >
> > > If you're using the Metadata plugin and inline rules:
> >
> > > 
> > > 
> >
> > > I've not actually tested it but it should work.
> >
> > > On Oct 11, 4:37 am, Phper  wrote:
> >
> > > > There are two input fields in a form, but only one of them is
> > > > required, they are not required at the same time. Either A or B is
> > > > required. ( A is required  OR B is required). In other words, a user
> > > > can input data to field A, or he can input data to filed B, but he
> can
> > > > not input data to Both A and B at the same time.
> >
> > > > How to implement this constraint in Jquery form validation?
>


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread d...@amystdesign.com

It will be confusing for someone filling out your form if you leave
both fields available at the same time, instead... when the user
enters text into one of the fields why don't you run an onChange or
onKeyPress check to see if they've entered something and if so,
disable/hide the other field .attr('disabled', disabled') or .hide()
or if they have deleted what's in the field to enable/hide the partner
field again... just remember to include null checks to unset the
disabling/hiding



On Oct 12, 3:55 am, Phper  wrote:
> Also, how to prevent a user filling out both fields?
>
> On Oct 12, 4:48 pm, Phper  wrote:
>
> > How to change the default position of an error message in Jquey form
> > validation plugin?
>
> > On Oct 12, 4:33 pm, Gordon  wrote:
>
> > > If you're using the Metadata plugin and inline rules:
>
> > > 
> > > 
>
> > > I've not actually tested it but it should work.
>
> > > On Oct 11, 4:37 am, Phper  wrote:
>
> > > > There are two input fields in a form, but only one of them is
> > > > required, they are not required at the same time. Either A or B is
> > > > required. ( A is required  OR B is required). In other words, a user
> > > > can input data to field A, or he can input data to filed B, but he can
> > > > not input data to Both A and B at the same time.
>
> > > > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread Phper

Also, how to prevent a user filling out both fields?

On Oct 12, 4:48 pm, Phper  wrote:
> How to change the default position of an error message in Jquey form
> validation plugin?
>
> On Oct 12, 4:33 pm, Gordon  wrote:
>
> > If you're using the Metadata plugin and inline rules:
>
> > 
> > 
>
> > I've not actually tested it but it should work.
>
> > On Oct 11, 4:37 am, Phper  wrote:
>
> > > There are two input fields in a form, but only one of them is
> > > required, they are not required at the same time. Either A or B is
> > > required. ( A is required  OR B is required). In other words, a user
> > > can input data to field A, or he can input data to filed B, but he can
> > > not input data to Both A and B at the same time.
>
> > > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread Phper

Also, how to prevent a user filling out both fields?

On Oct 12, 4:48 pm, Phper  wrote:
> How to change the default position of an error message in Jquey form
> validation plugin?
>
> On Oct 12, 4:33 pm, Gordon  wrote:
>
> > If you're using the Metadata plugin and inline rules:
>
> > 
> > 
>
> > I've not actually tested it but it should work.
>
> > On Oct 11, 4:37 am, Phper  wrote:
>
> > > There are two input fields in a form, but only one of them is
> > > required, they are not required at the same time. Either A or B is
> > > required. ( A is required  OR B is required). In other words, a user
> > > can input data to field A, or he can input data to filed B, but he can
> > > not input data to Both A and B at the same time.
>
> > > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread Phper

How to change the default position of an error message in Jquey form
validation plugin?

On Oct 12, 4:33 pm, Gordon  wrote:
> If you're using the Metadata plugin and inline rules:
>
> 
> 
>
> I've not actually tested it but it should work.
>
> On Oct 11, 4:37 am, Phper  wrote:
>
> > There are two input fields in a form, but only one of them is
> > required, they are not required at the same time. Either A or B is
> > required. ( A is required  OR B is required). In other words, a user
> > can input data to field A, or he can input data to filed B, but he can
> > not input data to Both A and B at the same time.
>
> > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread Gordon

If you're using the Metadata plugin and inline rules:




I've not actually tested it but it should work.

On Oct 11, 4:37 am, Phper  wrote:
> There are two input fields in a form, but only one of them is
> required, they are not required at the same time. Either A or B is
> required. ( A is required  OR B is required). In other words, a user
> can input data to field A, or he can input data to filed B, but he can
> not input data to Both A and B at the same time.
>
> How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-12 Thread Phper

No, I can not use radio. At the help of a veteran programmer, I was
able to write the following code and it works.

http://code.jquery.com/jquery-
latest.js">
http://dev.jquery.com/view/trunk/
plugins/validate/jquery.validate.js">






There is a minor problem.
I wanna change the default position of an alert message which is "This
field is required." by default. How to do it?

On Oct 12, 2:54 pm, Don Dunbar  wrote:
> I thought of a much simpler solution. If possible could you use radio
> buttons for those two choices in your HTML? In a radio button group
> selecting one automatically deselects other buttons in the group. Then you
> could just use one of the built in validation checks, as you already have
> done, to make sure one is checked.DED
>
> On Mon, Oct 12, 2009 at 1:43 AM, Phper  wrote:
>
> > I am not familiar with the syntax of Jquery plugin.
>
> > On Oct 12, 2:19 pm, Don Dunbar  wrote:
> > > Hi , I double checked on javascript's XOR operator and it only works with
> > > bitwise: so you will have to write your own XOR . This isn't hard :
> > [code]
> > > if (!foo != !bar)  [\code] should work for all elements.
> > >    or this
> > >    [code]if( ( foo && !bar ) || ( !foo && bar ) )[\code]
>
> > > For the validator method I haven't actually tried to run this but you can
> > > try this:[code]
> > >     $.validator.addMethod(
>
> > >     "onlyCheckOne",
> > >     function(value, elements) {
> > >         // but put whatever you're using to see if either is checked
> > > in the next line
> > >         return  this.optional(value) ||  elements[o]:checked XOR
> > > elements[1]:checked;
> > >     },
> > >     "Please check either participations or days, but not both"
> > > )[/code] note change XOR to whatever method you decide to use.
>
> > > Then add the check to your rules.
> > > DED
>
> > > On Mon, Oct 12, 2009 at 12:36 AM, Phper  wrote:
>
> > > > http://code.jquery.com/jquery-
> > > > latest.js">
> > > > http://dev.jquery.com/view/trunk/
> > > > plugins/validate/jquery.validate.js">
>
> > > > 
> > > > 
> > > > 
>
> > > > As you can see from the code above, "title", "content", "evaluation",
> > > > "prices" and "multi" are required. All of them are required. But there
> > > > are additional two fields, which are "participations" and "days". Only
> > > > one of them is required. Either "participations" or "days" is
> > > > required. How to write this code?
>
> > > > On Oct 12, 10:17 am, Phper  wrote:
> > > > > A good clue. But I still don't know where to write the "if"
> > statement.
> > > > > It would be good if you can give me an example.
>
> > > > > On Oct 11, 10:57 pm, Don Dunbar  wrote:
>
> > > > > > Hi, if you are using the validation plugin, I believe it has a
> > function
> > > > > > "addMethod" that allows you to write your own method for the
> > > > validation. It
> > > > > > requires a name (javascript identifier), a method to check input
> > > > against (
> > > > > > in your case A and B would be checked for completion) and a message
> > to
> > > > > > display when there is an error (i.e. neither A nor B is filled out,
> > or
> > > > both
> > > > > > are). You can get the details for using the "addMethod" 

[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Don Dunbar
I thought of a much simpler solution. If possible could you use radio
buttons for those two choices in your HTML? In a radio button group
selecting one automatically deselects other buttons in the group. Then you
could just use one of the built in validation checks, as you already have
done, to make sure one is checked.DED

On Mon, Oct 12, 2009 at 1:43 AM, Phper  wrote:

>
>
> I am not familiar with the syntax of Jquery plugin.
>
> On Oct 12, 2:19 pm, Don Dunbar  wrote:
> > Hi , I double checked on javascript's XOR operator and it only works with
> > bitwise: so you will have to write your own XOR . This isn't hard :
> [code]
> > if (!foo != !bar)  [\code] should work for all elements.
> >or this
> >[code]if( ( foo && !bar ) || ( !foo && bar ) )[\code]
> >
> > For the validator method I haven't actually tried to run this but you can
> > try this:[code]
> > $.validator.addMethod(
> >
> > "onlyCheckOne",
> > function(value, elements) {
> > // but put whatever you're using to see if either is checked
> > in the next line
> > return  this.optional(value) ||  elements[o]:checked XOR
> > elements[1]:checked;
> > },
> > "Please check either participations or days, but not both"
> > )[/code] note change XOR to whatever method you decide to use.
> >
> > Then add the check to your rules.
> > DED
> >
> > On Mon, Oct 12, 2009 at 12:36 AM, Phper  wrote:
> >
> > > http://code.jquery.com/jquery-
> > > latest.js">
> > > http://dev.jquery.com/view/trunk/
> > > plugins/validate/jquery.validate.js">
> >
> > > 
> > > 
> > > 
> >
> > > As you can see from the code above, "title", "content", "evaluation",
> > > "prices" and "multi" are required. All of them are required. But there
> > > are additional two fields, which are "participations" and "days". Only
> > > one of them is required. Either "participations" or "days" is
> > > required. How to write this code?
> >
> > > On Oct 12, 10:17 am, Phper  wrote:
> > > > A good clue. But I still don't know where to write the "if"
> statement.
> > > > It would be good if you can give me an example.
> >
> > > > On Oct 11, 10:57 pm, Don Dunbar  wrote:
> >
> > > > > Hi, if you are using the validation plugin, I believe it has a
> function
> > > > > "addMethod" that allows you to write your own method for the
> > > validation. It
> > > > > requires a name (javascript identifier), a method to check input
> > > against (
> > > > > in your case A and B would be checked for completion) and a message
> to
> > > > > display when there is an error (i.e. neither A nor B is filled out,
> or
> > > both
> > > > > are). You can get the details for using the "addMethod" function at
> the
> > > > > jQuery Docs page.http://docs.jquery.com/Plugins/Validation
> > > > > The page lists demos and the function you need is toward the bottom
> of
> > > the
> > > > > page.
> >
> > > > > The logic is fairly straight forward :  when the form is being
> filled
> > > out
> > > > > listen for when A and B have focus, remember if either is checked
> or
> > > ignored
> > > > > and check to make sure both are not simultaneously filled out.
> Check
> > > this on
> > > > > submit as well.
> >
> > > > > Good luck,
> > > > > DED
> >
> > > > > On Sun, Oct 11, 2009 at 7:42 AM, Phper 
> wrote:
> >
> > > > > > How can I write the code in the context of Jquery validate
> function?
> >
> > > > > > On Oct 11, 12:43 pm, Don Dunbar  wrote:
> > > > > > > Hi, javascript has an 'xor' operator. It works just like 'or'
> in an
> > > 'if'
> > > > > > > statement except in 'xor' only one side can be true. In a
> normal
> > > 'or'
> > > > > > > statement either side can be true or both can. So you probably
> want
> > > to do
> > > > > > > something like: if ( A XOR B) { } .  Then only one can be true
> to
> > > > > > continue
> > > > > > > if both are true the statement returns 'false'.Hope this helps.
> > > > > > > DED
> >
> > > > > > > On Sat, Oct 10, 2009 at 10:37 PM, Phper <
> hi.steven...@gmail.com>
> > > wrote:
> >
> > > > > > > > There are two input fields in a form, but only one of them is
> > > > > > > > required, they are not required at the same time. Either A or
> B
> > > is

[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Phper


I am not familiar with the syntax of Jquery plugin.

On Oct 12, 2:19 pm, Don Dunbar  wrote:
> Hi , I double checked on javascript's XOR operator and it only works with
> bitwise: so you will have to write your own XOR . This isn't hard :   [code]
> if (!foo != !bar)  [\code] should work for all elements.
>    or this
>    [code]if( ( foo && !bar ) || ( !foo && bar ) )[\code]
>
> For the validator method I haven't actually tried to run this but you can
> try this:[code]
>     $.validator.addMethod(
>
>     "onlyCheckOne",
>     function(value, elements) {
>         // but put whatever you're using to see if either is checked
> in the next line
>         return  this.optional(value) ||  elements[o]:checked XOR
> elements[1]:checked;
>     },
>     "Please check either participations or days, but not both"
> )[/code] note change XOR to whatever method you decide to use.
>
> Then add the check to your rules.
> DED
>
> On Mon, Oct 12, 2009 at 12:36 AM, Phper  wrote:
>
> > http://code.jquery.com/jquery-
> > latest.js">
> > http://dev.jquery.com/view/trunk/
> > plugins/validate/jquery.validate.js">
>
> > 
> > 
> > 
>
> > As you can see from the code above, "title", "content", "evaluation",
> > "prices" and "multi" are required. All of them are required. But there
> > are additional two fields, which are "participations" and "days". Only
> > one of them is required. Either "participations" or "days" is
> > required. How to write this code?
>
> > On Oct 12, 10:17 am, Phper  wrote:
> > > A good clue. But I still don't know where to write the "if" statement.
> > > It would be good if you can give me an example.
>
> > > On Oct 11, 10:57 pm, Don Dunbar  wrote:
>
> > > > Hi, if you are using the validation plugin, I believe it has a function
> > > > "addMethod" that allows you to write your own method for the
> > validation. It
> > > > requires a name (javascript identifier), a method to check input
> > against (
> > > > in your case A and B would be checked for completion) and a message to
> > > > display when there is an error (i.e. neither A nor B is filled out, or
> > both
> > > > are). You can get the details for using the "addMethod" function at the
> > > > jQuery Docs page.http://docs.jquery.com/Plugins/Validation
> > > > The page lists demos and the function you need is toward the bottom of
> > the
> > > > page.
>
> > > > The logic is fairly straight forward :  when the form is being filled
> > out
> > > > listen for when A and B have focus, remember if either is checked or
> > ignored
> > > > and check to make sure both are not simultaneously filled out. Check
> > this on
> > > > submit as well.
>
> > > > Good luck,
> > > > DED
>
> > > > On Sun, Oct 11, 2009 at 7:42 AM, Phper  wrote:
>
> > > > > How can I write the code in the context of Jquery validate function?
>
> > > > > On Oct 11, 12:43 pm, Don Dunbar  wrote:
> > > > > > Hi, javascript has an 'xor' operator. It works just like 'or' in an
> > 'if'
> > > > > > statement except in 'xor' only one side can be true. In a normal
> > 'or'
> > > > > > statement either side can be true or both can. So you probably want
> > to do
> > > > > > something like: if ( A XOR B) { } .  Then only one can be true to
> > > > > continue
> > > > > > if both are true the statement returns 'false'.Hope this helps.
> > > > > > DED
>
> > > > > > On Sat, Oct 10, 2009 at 10:37 PM, Phper 
> > wrote:
>
> > > > > > > There are two input fields in a form, but only one of them is
> > > > > > > required, they are not required at the same time. Either A or B
> > is
> > > > > > > required. ( A is required  OR B is required). In other words, a
> > user
> > > > > > > can input data to field A, or he can input data to filed B, but
> > he can
> > > > > > > not input data to Both A and B at the same time.
>
> > > > > > > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Satyakaran

whats the problem? just check one field, it it is filled then do not
check other.
may be your problem is something else

On Oct 11, 8:37 am, Phper  wrote:
> There are two input fields in a form, but only one of them is
> required, they are not required at the same time. Either A or B is
> required. ( A is required  OR B is required). In other words, a user
> can input data to field A, or he can input data to filed B, but he can
> not input data to Both A and B at the same time.
>
> How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Don Dunbar
Hi , I double checked on javascript's XOR operator and it only works with
bitwise: so you will have to write your own XOR . This isn't hard :   [code]
if (!foo != !bar)  [\code] should work for all elements.
   or this
   [code]if( ( foo && !bar ) || ( !foo && bar ) )[\code]

For the validator method I haven't actually tried to run this but you can
try this:[code]
$.validator.addMethod(

"onlyCheckOne",
function(value, elements) {
// but put whatever you're using to see if either is checked
in the next line
return  this.optional(value) ||  elements[o]:checked XOR
elements[1]:checked;
},
"Please check either participations or days, but not both"
)[/code] note change XOR to whatever method you decide to use.

Then add the check to your rules.
DED


On Mon, Oct 12, 2009 at 12:36 AM, Phper  wrote:

>
> http://code.jquery.com/jquery-
> latest.js">
> http://dev.jquery.com/view/trunk/
> plugins/validate/jquery.validate.js">
>
> 
> 
> 
>
> As you can see from the code above, "title", "content", "evaluation",
> "prices" and "multi" are required. All of them are required. But there
> are additional two fields, which are "participations" and "days". Only
> one of them is required. Either "participations" or "days" is
> required. How to write this code?
>
> On Oct 12, 10:17 am, Phper  wrote:
> > A good clue. But I still don't know where to write the "if" statement.
> > It would be good if you can give me an example.
> >
> > On Oct 11, 10:57 pm, Don Dunbar  wrote:
> >
> > > Hi, if you are using the validation plugin, I believe it has a function
> > > "addMethod" that allows you to write your own method for the
> validation. It
> > > requires a name (javascript identifier), a method to check input
> against (
> > > in your case A and B would be checked for completion) and a message to
> > > display when there is an error (i.e. neither A nor B is filled out, or
> both
> > > are). You can get the details for using the "addMethod" function at the
> > > jQuery Docs page.http://docs.jquery.com/Plugins/Validation
> > > The page lists demos and the function you need is toward the bottom of
> the
> > > page.
> >
> > > The logic is fairly straight forward :  when the form is being filled
> out
> > > listen for when A and B have focus, remember if either is checked or
> ignored
> > > and check to make sure both are not simultaneously filled out. Check
> this on
> > > submit as well.
> >
> > > Good luck,
> > > DED
> >
> > > On Sun, Oct 11, 2009 at 7:42 AM, Phper  wrote:
> >
> > > > How can I write the code in the context of Jquery validate function?
> >
> > > > On Oct 11, 12:43 pm, Don Dunbar  wrote:
> > > > > Hi, javascript has an 'xor' operator. It works just like 'or' in an
> 'if'
> > > > > statement except in 'xor' only one side can be true. In a normal
> 'or'
> > > > > statement either side can be true or both can. So you probably want
> to do
> > > > > something like: if ( A XOR B) { } .  Then only one can be true to
> > > > continue
> > > > > if both are true the statement returns 'false'.Hope this helps.
> > > > > DED
> >
> > > > > On Sat, Oct 10, 2009 at 10:37 PM, Phper 
> wrote:
> >
> > > > > > There are two input fields in a form, but only one of them is
> > > > > > required, they are not required at the same time. Either A or B
> is
> > > > > > required. ( A is required  OR B is required). In other words, a
> user
> > > > > > can input data to field A, or he can input data to filed B, but
> he can
> > > > > > not input data to Both A and B at the same time.
> >
> > > > > > How to implement this constraint in Jquery form validation?
>


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Phper

http://code.jquery.com/jquery-
latest.js">
http://dev.jquery.com/view/trunk/
plugins/validate/jquery.validate.js">





As you can see from the code above, "title", "content", "evaluation",
"prices" and "multi" are required. All of them are required. But there
are additional two fields, which are "participations" and "days". Only
one of them is required. Either "participations" or "days" is
required. How to write this code?

On Oct 12, 10:17 am, Phper  wrote:
> A good clue. But I still don't know where to write the "if" statement.
> It would be good if you can give me an example.
>
> On Oct 11, 10:57 pm, Don Dunbar  wrote:
>
> > Hi, if you are using the validation plugin, I believe it has a function
> > "addMethod" that allows you to write your own method for the validation. It
> > requires a name (javascript identifier), a method to check input against (
> > in your case A and B would be checked for completion) and a message to
> > display when there is an error (i.e. neither A nor B is filled out, or both
> > are). You can get the details for using the "addMethod" function at the
> > jQuery Docs page.http://docs.jquery.com/Plugins/Validation
> > The page lists demos and the function you need is toward the bottom of the
> > page.
>
> > The logic is fairly straight forward :  when the form is being filled out
> > listen for when A and B have focus, remember if either is checked or ignored
> > and check to make sure both are not simultaneously filled out. Check this on
> > submit as well.
>
> > Good luck,
> > DED
>
> > On Sun, Oct 11, 2009 at 7:42 AM, Phper  wrote:
>
> > > How can I write the code in the context of Jquery validate function?
>
> > > On Oct 11, 12:43 pm, Don Dunbar  wrote:
> > > > Hi, javascript has an 'xor' operator. It works just like 'or' in an 'if'
> > > > statement except in 'xor' only one side can be true. In a normal 'or'
> > > > statement either side can be true or both can. So you probably want to 
> > > > do
> > > > something like: if ( A XOR B) { } .  Then only one can be true to
> > > continue
> > > > if both are true the statement returns 'false'.Hope this helps.
> > > > DED
>
> > > > On Sat, Oct 10, 2009 at 10:37 PM, Phper  wrote:
>
> > > > > There are two input fields in a form, but only one of them is
> > > > > required, they are not required at the same time. Either A or B is
> > > > > required. ( A is required  OR B is required). In other words, a user
> > > > > can input data to field A, or he can input data to filed B, but he can
> > > > > not input data to Both A and B at the same time.
>
> > > > > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Phper

A good clue. But I still don't know where to write the "if" statement.
It would be good if you can give me an example.

On Oct 11, 10:57 pm, Don Dunbar  wrote:
> Hi, if you are using the validation plugin, I believe it has a function
> "addMethod" that allows you to write your own method for the validation. It
> requires a name (javascript identifier), a method to check input against (
> in your case A and B would be checked for completion) and a message to
> display when there is an error (i.e. neither A nor B is filled out, or both
> are). You can get the details for using the "addMethod" function at the
> jQuery Docs page.http://docs.jquery.com/Plugins/Validation
> The page lists demos and the function you need is toward the bottom of the
> page.
>
> The logic is fairly straight forward :  when the form is being filled out
> listen for when A and B have focus, remember if either is checked or ignored
> and check to make sure both are not simultaneously filled out. Check this on
> submit as well.
>
> Good luck,
> DED
>
> On Sun, Oct 11, 2009 at 7:42 AM, Phper  wrote:
>
> > How can I write the code in the context of Jquery validate function?
>
> > On Oct 11, 12:43 pm, Don Dunbar  wrote:
> > > Hi, javascript has an 'xor' operator. It works just like 'or' in an 'if'
> > > statement except in 'xor' only one side can be true. In a normal 'or'
> > > statement either side can be true or both can. So you probably want to do
> > > something like: if ( A XOR B) { } .  Then only one can be true to
> > continue
> > > if both are true the statement returns 'false'.Hope this helps.
> > > DED
>
> > > On Sat, Oct 10, 2009 at 10:37 PM, Phper  wrote:
>
> > > > There are two input fields in a form, but only one of them is
> > > > required, they are not required at the same time. Either A or B is
> > > > required. ( A is required  OR B is required). In other words, a user
> > > > can input data to field A, or he can input data to filed B, but he can
> > > > not input data to Both A and B at the same time.
>
> > > > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Don Dunbar
Hi, if you are using the validation plugin, I believe it has a function
"addMethod" that allows you to write your own method for the validation. It
requires a name (javascript identifier), a method to check input against (
in your case A and B would be checked for completion) and a message to
display when there is an error (i.e. neither A nor B is filled out, or both
are). You can get the details for using the "addMethod" function at the
jQuery Docs page.
http://docs.jquery.com/Plugins/Validation
The page lists demos and the function you need is toward the bottom of the
page.

The logic is fairly straight forward :  when the form is being filled out
listen for when A and B have focus, remember if either is checked or ignored
and check to make sure both are not simultaneously filled out. Check this on
submit as well.

Good luck,
DED

On Sun, Oct 11, 2009 at 7:42 AM, Phper  wrote:

>
> How can I write the code in the context of Jquery validate function?
>
> On Oct 11, 12:43 pm, Don Dunbar  wrote:
> > Hi, javascript has an 'xor' operator. It works just like 'or' in an 'if'
> > statement except in 'xor' only one side can be true. In a normal 'or'
> > statement either side can be true or both can. So you probably want to do
> > something like: if ( A XOR B) { } .  Then only one can be true to
> continue
> > if both are true the statement returns 'false'.Hope this helps.
> > DED
> >
> > On Sat, Oct 10, 2009 at 10:37 PM, Phper  wrote:
> >
> > > There are two input fields in a form, but only one of them is
> > > required, they are not required at the same time. Either A or B is
> > > required. ( A is required  OR B is required). In other words, a user
> > > can input data to field A, or he can input data to filed B, but he can
> > > not input data to Both A and B at the same time.
> >
> > > How to implement this constraint in Jquery form validation?
>


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Phper

How can I write the code in the context of Jquery validate function?

On Oct 11, 12:43 pm, Don Dunbar  wrote:
> Hi, javascript has an 'xor' operator. It works just like 'or' in an 'if'
> statement except in 'xor' only one side can be true. In a normal 'or'
> statement either side can be true or both can. So you probably want to do
> something like: if ( A XOR B) { } .  Then only one can be true to continue
> if both are true the statement returns 'false'.Hope this helps.
> DED
>
> On Sat, Oct 10, 2009 at 10:37 PM, Phper  wrote:
>
> > There are two input fields in a form, but only one of them is
> > required, they are not required at the same time. Either A or B is
> > required. ( A is required  OR B is required). In other words, a user
> > can input data to field A, or he can input data to filed B, but he can
> > not input data to Both A and B at the same time.
>
> > How to implement this constraint in Jquery form validation?


[jQuery] Re: Only one of two fields is required. How to implement this logic in Jquery form validation?

2009-10-11 Thread Don Dunbar
Hi, javascript has an 'xor' operator. It works just like 'or' in an 'if'
statement except in 'xor' only one side can be true. In a normal 'or'
statement either side can be true or both can. So you probably want to do
something like: if ( A XOR B) { } .  Then only one can be true to continue
if both are true the statement returns 'false'.Hope this helps.
DED

On Sat, Oct 10, 2009 at 10:37 PM, Phper  wrote:

>
> There are two input fields in a form, but only one of them is
> required, they are not required at the same time. Either A or B is
> required. ( A is required  OR B is required). In other words, a user
> can input data to field A, or he can input data to filed B, but he can
> not input data to Both A and B at the same time.
>
> How to implement this constraint in Jquery form validation?