I have a form with a status field.
If this status is "3", I have other fields hidden and a message to contact us is displayed.
However, the submit button is still present. How do I hide the submit button also, if the status is 3?
I have a form with a status field.
If this status is "3", I have other fields hidden and a message to contact us is displayed.
However, the submit button is still present. How do I hide the submit button also, if the status is 3?
Hi Chris,
You can use this if you want the button to be hidden or shown as soon as the field holds "3" or does not hold "3".
$(document).ready(function() { $("#q71 input").keyup(function(){ if($(this).val() == "3"){ $(".Submit").hide(); }else{ $(".Submit").show(); } }); });
The way I do it is with JavaScript.
Replace the "#Field1" with the ID of the "status" form field, and add the code to the custom javaScript section of the form.
$(document).ready(function() { $("#Field1").on("change, input", function(){ if($(this).val() === "3"){ $(".Submit").hide(); }else{ $(".Submit").show(); } }); });
If did but it is not hiding. I have the following:
$(document).ready(function() {
$("q71").on("change, input", function(){
if($(this).val() === "3"){
$(".Submit").hide();
}else{
$(".Submit").show();
}
});
});
Hey Chris,
I assume that the status filed is just a plain text field? If so this code should work for you. It's a little different from what I posted before because I realized that you might have a form where the status is already set.
Let me know if this works.
$(document).ready(function() { toggleSubmit(); $("#Field71").on("change, input", toggleSubmit); }); function toggleSubmit(){ var status = $("#Field71"); if($(status).val() === "3"){ $(".Submit").hide(); }else{ $(".Submit").show(); } }
Hi Chris, you missed the pound sign in front of the field name. You need "#q71" instead of "q71". An easy mistake to make in jQuery.
I saw that and and added. Still nothing, lol. I now have the following:
$(document).ready(function() {
$("#q71").on("change, input", function(){
if($(this).val() === "3"){
$(".Submit").hide();
}else{
$(".Submit").show();
}
});
});
There are a couple of other things different from how I usually do it.
If those changes don't fix it I'll put together a test form and then paste my code from it.
I just saw Brian's solution. It's strength/weakness is that it only works for keyboard changes. Just something to be aware of--that might be exactly what you want.
I made the changes and still no go. :-(
I just tested the following code on forms 10.3. Don't forget to substitute the "#q1" with the ID of the field on your form. Laserfiche numbers all the fields on your form and sets the id attribute of the field to a "q" followed by that number. This should work whether the field is filled in from a lookup, from Javascript, or with the keyboard.
Be aware that this will work for a fill-in field. If you're working with a dropdown or radio button, it'll look slightly different.
$(document).ready(function() { $("#q1").on("change", "input", function(){ if($(this).val() === "3"){ $(".Submit").hide(); }else{ $(".Submit").show(); } }); });
Thank for all you help. Still not working. I did notice where your values are blue, mine are red.
What kind of field is #q71 on your form?
This only works for fill-in fields. You also have to move the cursor out of the field before the change event will be triggered.
No need to worry about the color differences. The colors will be different depending on what you type the code into. What matters is the code itself.
Q71 is a field populated from a look up table, based on another field's value.
Hmmm! I thought that would work.
Is it a regular "single line" field other than being filled form a lookup?
yes, it is a single line field.
The only thing I can think of that could go wrong there is if the lookup field is inserting something invisible like space characters after or before the "3" with which it populates the field.
The following text does two things:
Go ahead and try this code. Remember to substitute your field name for my "#q1".
If it works, just remove the "alert" statement and you're good to go. If not, let me know whether the alert box pops up, and if so, what it shows.
$(document).ready(function() { $("#q1").on("change", "input", function(){ alert(`Field value is *${$(this).val()}*`); if(trim($(this).val()) === "3"){ $(".Submit").hide(); }else{ $(".Submit").show(); } }); });
One more thing, note that the string in the alert statement is enclosed in back ticks, not single quote marks. If you copy and paste the text you won't have to worry about that, of course.
I am completely stumped. This did not work either. I got no alert.
$(document).ready(function() {
$("#q71").on("change", "input", function(){
alert(`Field value is *${$(this).val()}*`);
if(trim($(this).val()) === "3"){
$(".Submit").hide();
}else{
$(".Submit").show();
}
});
});
Ok, now we know more about what's going on. If the alert box didn't appear, then the event didn't fire.
While you're editing the javascript code, you should see fields to the right of the code. Above each field is a blue bar (at least on my version, which is Laserfiche 10.3). That bar tells you what the "id" is of the field. On your screen, what is the "id" of the field you want to watch? on my example, it's "q1".
We got it working.
The Status Field was a part of a table and the table also had a class of "status", preventing the java action to work. Thank you all for jumping on this!!
Woo-hoo Congratulations!! You worked hard for that one!