Firstly apologies if I don't explain this correctly!
I have a contour form (3.0.24-Build.31) that has two datepickers on it and what I'm trying to acheive is to stop the user from submitting the form if they haven't selected at least one of the dates (they can select both if they wish).
I'm wondering if there's something 'in' Contour that'll do this based on sort of 'conditional' values?
Can't remember exactly - But it should be possible to setup some conditional stuff in Contour.
But another way around it could be to add some jQuery to validate if one or the other field has been populated outside the Contour scope - It should be possible to target the #contour id and then keep an eye on those fields and then append or prepend messages if needed different places in the DOM.
Thanks for your time. I can't see anything in the Conditional 'stuff' that would do the job I can show/hide fields based upon other fields but I always want both fields visible. Once again I completely overlooked jQuery (!) I'll have a play with that! Thinking about it though I don't know when to fire the validation......
So my next question is this......I've removed (in Contour) the mandatory flag on these fields and I'm going to control their validation in script.....how would I then stop the form from actually submitting if I need to?
If you hook into the submit event instead you should be able to handle it like the example displayed here http://api.jquery.com/submit/ - Try having a look at the first demo.
Ok, can you show some more HTML code so it's possible to see the whole context? I suspect it's just because you need to write something like $(".contourNavigation form").submit()...but need to see the context to be more accurate :)
Make user at least select one value
Hi all,
Firstly apologies if I don't explain this correctly!
I have a contour form (3.0.24-Build.31) that has two datepickers on it and what I'm trying to acheive is to stop the user from submitting the form if they haven't selected at least one of the dates (they can select both if they wish).
I'm wondering if there's something 'in' Contour that'll do this based on sort of 'conditional' values?
Anybody have any ideas?
Thanks,
Craig
Hi Craig
Can't remember exactly - But it should be possible to setup some conditional stuff in Contour.
But another way around it could be to add some jQuery to validate if one or the other field has been populated outside the Contour scope - It should be possible to target the #contour id and then keep an eye on those fields and then append or prepend messages if needed different places in the DOM.
Hope this makes sense.
/Jan
Hi Jan,
Thanks for your time. I can't see anything in the Conditional 'stuff' that would do the job I can show/hide fields based upon other fields but I always want both fields visible. Once again I completely overlooked jQuery (!) I'll have a play with that! Thinking about it though I don't know when to fire the validation......
Any thoughts?
Hi Craig
Yeah it's also one of those things that are easy to overlook sometimes :) - You could do it on "Submit" perhaps?
/Jan
To be honest I don't know how to hook into the submit button!
Hi Craig
You should be able to do something like
If my memory is correct there should be a form tag rendered...or is it part of a webform?
/Jan
Hi Jan,
This is what of got that sorta works (need to sort the variable setting).
$(".contourNavigation input[type=submit]").click(function( event ) {
var submission;
submission = "true";
$(".datepickerfield").each(function(index) {
if ( $( this ).val() == "")
{
submission = "false";
}
if (submission = "false")
{
alert("Both not populated");
}
});
});
So my next question is this......I've removed (in Contour) the mandatory flag on these fields and I'm going to control their validation in script.....how would I then stop the form from actually submitting if I need to?
Hi Craig
If you hook into the submit event instead you should be able to handle it like the example displayed here http://api.jquery.com/submit/ - Try having a look at the first demo.
Hope this helps.
/Jan
That's what I was looking at! Spooky.
but event.preventDefault()
Isn't stopping the form from submitting. So close but yet so far away!
Have you changed your code since the former post? If so please share :)
/Jan
Hi Jan,
Apologies for the delay:
Here's the code that I've got so far. I'm hitting the 'Submission = "false"' area but the preventDefault isn't stopping the form from actually firing.
<script>
$(".contourNavigation input[type=submit]").click(function( event ) {
var submission;
submission = "true";
$(".datepickerfield").each(function(index) {
if ( $( this ).val() == "")
{
submission = "false";
}
});
if (submission = "false")
{
alert("Both not populated");
event.preventDefault();
}
});
</script>
Hi Craig
Have you tried using .submit() instead of click() as I suggested in a former post?
/Jan
hi Jan,
Sorry I didn't even notice you'd typed 'submit' but sadly I can't seem to get a handle on the button firing using submit: For instance:
$(".contourNavigation input[type=submit]").click(function( event ) {
alert("Button Pressed");
});
Will fire when the button is clicked. Whereas
$("#contour_form_RegisterNow").submit(function( event ) {
alert("Button Pressed");
});
Doesn't fire the event. I just can't seem to 'get' the button using the submit function......
It's strange that the form itself doesn't have an ID or class
<form action="" enctype="multipart/form-data" method="post" novalidate="novalidate">
Hi Craig
Ok, can you show some more HTML code so it's possible to see the whole context? I suspect it's just because you need to write something like $(".contourNavigation form").submit()...but need to see the context to be more accurate :)
/Jan
Apologies for the size: (!)
Hi Craig
Ok, try targetting this
I think that should work.
/Jan
Argh!
Thanks but that doesn't fire!
<script>
$(".registernow input[type=submit]").click('submit',function(event){
//Try your code here
alert('Hello');
event.preventDefault();
});
</script>
This does fire on the button click but event.preventDefault() doesn't stop the form from posting!
Confused.com!
Hi Craig
Does it help any to switch the position of your alert and your event.preventDefault() so it's first in the code?
/Jan
Argh!
Nah, it doesn't fire I move the code so that's it's first.
:(
is working on a reply...