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

Question

Question

Forms - Display alert when submit button is clicked if field is filled by a lookup rule

asked on January 19 Show version history

Hello,

I've managed to configure a lookup rule on a form that looks at the 'worker_instance_data' view in the Forms database and fills a form field if I get a result. If I get result, it's indicating that the initiator has at least one other instance of this forms process already assigned to them as a user task. When this happens, I display a message at the top of the form using a custom HTML field and a field rule telling the user to go finish that instance, but I'd also like to display an alert when the user clicks the submit button, and not allow the submission to occur.

I've tried modifying some of the code I've found in other posts but haven't had any luck. In short, if a field that gets filled by a lookup rule has data in it when the user tries to submit the form, I want an alert to pop up, and for the submit button to not actually submit the form.

Is this something that can be done?

0 0

Answer

SELECTED ANSWER
replied on January 19

This works for me.  Alternatively, if there is a value in the lookup field then a field rule shows the error.

$(document).ready(function() {
//  Disable submit button and display error fields if (#q33) employee folder was found on lookup
//  There should be no duplicate SSN or employee number
    $('#q33 input').change(function() {
        if ($('#q33 input').val() == '') {         // if lookup failed
            $('.Submit').prop("disabled", false);  // enable submit
            $('#q33, #q34').addClass("hidden");    // hide error fields         
        } else {
            $('.Submit').prop("disabled", true);   // disable submit
            $('#q33, #q34').removeClass("hidden"); // show error fields
        }
    });
});
 

1 0
replied on January 19 Show version history

This worked. I tried a variation of this earlier but I must have been missing something. Copied, pasted, replaced your field IDs with mine and it worked immediately. Thanks!

0 0

Replies

replied on January 19

Jacob,  I'd love to see that view.  Jim.

0 0
replied on January 19 Show version history

I should probably explain my process a little bit. This process involves 3 forms. This is a vehicle inspection process, in which a driver needs to perform a morning inspection prior to driving, and an inspection at the end of the day when they're done. What we do is allow the driver to submit this form as many times as they want, and it gets routed back to their inbox until they give us their ending miles, and fill out a signature field. The customer didn't want the 'save as draft' button on the form - they just wanted one button, so we opted to do it this way. 

There are 4 pieces of information I'm using to perform this lookup. We populate a driver name field with {/_currentuser_display}, we populate a hidden field called Task Status with the value '2,' and we populate a hidden field called Form Name with value 'Form2 Name.' My lookup rule looks like this:
 

The task_owner_displayname column in the view contains the same value that's being populated by in our Driver Name field - in this case, it's the name of the driver who's been assigned this task because they haven't provided the ending miles and they haven't signed it. The form_name column contains the name of the form that's assigned to the user - we assign a separate form (Form2) to the driver after their initial submission that doesn't contain any of these hidden fields. The task_status column appears to simply contain the value '2' when I look at a row that pertains to this user task (I'm not sure that I need this column now that I'm describing it). 

So, if we find a match and fill that form field with what's in the step_name column, it seems to indicate that this user still has a user task to complete within this process. If the Previous Step Name field is not blank (because the lookup populated it), I show a custom HTML field with a message saying something like 'you still have an inspection to complete. Please go to your Forms inbox and complete it.'

Once the driver has provided the ending miles and signed the form, the form gets sent to a repair team if anything was marked wrong with the vehicle. The repair team gets Form3 assigned to them. 

There could be plenty of holes in this - I've tested it quite a bit today and it seems to be working, but I'll fully admit that this isn't necessarily a great solution. This customer really doesn't want this form to be submitted if the user has an uncompleted inspection still sitting out there, and this is what I've come up with in the last day.

EDIT: Sorry, didn't even list the name of the view. The name of the view is worker_instance_data in the Forms database.

1 0
replied on January 20 Show version history

Thanks Muchly

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

Sign in to reply to this post.