You are viewing limited content. For full access, please sign in.

Question

Question

Is it possible to generate an error based on a value in a read-only field?

asked on June 2, 2020

I'm working on a form for donation of leave, where an employee can donate up to a combined 24 hours of vacation and comp time to another employee when they need it and qualify for donations.

I have a field set up to calculate the sum of those two fields, and the error I've set up via the Error Messaging tab generates just fine when the sum is greater then 24, but the moment I make the field read-only, it no longer appears. Is there any way around this? If it's helpful, all three fields below are number fields with their values restricted from 0-24, and the error is set to generate when the value exceeds the maximum.

I don't necessarily need to display their total, I just need some sort of error to pop up and prevent them from submitting if their combined total exceeds 24. Any advice?

0 0

Replies

replied on June 4, 2020

Hi Dylan,

If you set the maximum value on the number field to 24 and then apply the CSS class "readonly-required-field", this JavaScript will disable the submit button when it has the error, and re-enable it on success.

$(document).ready(function() {
  $(".required-readonly-field input").parsley().on("field:success", function() {
    $("input.action-btn").prop("disabled",false);
  });
  $(".required-readonly-field input").parsley().on("field:error", function() {
    $("input.action-btn").prop("disabled",true);
  });
});

FYI you cannot have multiple of these fields on the same form. If you do, then if both fields have errors and then one is fixed while the other still has an error, then the submit button will be enabled when it shouldn't be.

3 0
replied on June 10, 2020

It's amazing how many people don't say thank you, or up vote your reply.  If it's any consolation I've added your reply to my how-to document.  Thanks.

1 0
replied on June 10, 2020

Haha thanks man. It happens. Sometimes things don't work for their situation or they get busy and come back later. Dylan's been quite polite to me on other posts.

0 0
replied on June 10, 2020

The "getting busy and coming back later" is exactly what happened here, haha. I didn't even see the notification that you responded to this Jim. I found a different solution in the meantime (it was as simple as making that read-only field required, surprisingly enough), but that code to disable the submit button based on other criteria is definitely useful! Thanks as always for the assistance!!!

2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.