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

Question

Question

Creating a class for writing javascript code.

asked on November 17

Hello, 

I am using the below JS code to clear fields when a previously submitted form comes back after correction for approval the second time. When it comes back for approval this time I need a few fields to be cleared like Reviewer's decision (clear previous decision so they can enter the new decision) and their comments.

$(document).ready(function() {
    $('.clearThisField').each(function() {
     

  $(this).find('input').val(''); // Clear single line fields.
  $(this).find('select').val(''); // Clear drop-down fields.
       
    });
});
 

The above code looks good to me but it is not doing anything at the moment. Is it because the class that I am using was created as a CSS class? I am not sure if i have to create classes separately for JavaScript. Please help me better understand this. Thank you.

0 0

Replies

replied on November 17

I found that .val() can be unpredictable try 

 $(this).find('input').prop("value", ''); // Clear single line fields.

0 0
replied on November 17

Thank you for the suggestion. I believe in my case the code is not an issue because I tried your suggestion as well and it did not work. I think I am doing something wrong in setting up the class for the field. I have set up the class for the field under advanced > CSS classes. Is that where I should be setting up the class for using it with JavaScript ? 

0 0
replied on November 17

Yes that class is used by JS.  Don't put a period in front of the class name in the CSS classes field.

0 0
replied on November 17

Just confirming - is this in the Classic designer or the Modern designer?  Because this code should work in Classic, but won't work in Modern.

0 0
replied on November 20

Hello, 

I think you are correct I am not using the classic designer and as a result it is not working. Do you happen to know how I would do this in the modern designer ?

Thank you.

0 0
replied on November 20

Something like this should work in the Modern Designer: 

var fieldsToClear = LFForm.findFieldsByClassName("clearThisField");
LFForm.setFieldValues(fieldsToClear, "");

Note that you do need to be on version 11.0.2212 with Hotfix 1014419 installed (or on version 11.0.2307) in order to have the findFieldsByClassName function available.

1 0
replied on November 20

Right the code that you provided works i think but my process kind of stops and doesn't do any thing after this code runs.

 My process is like this, first the initiator submits their form to the approver, then the approver receives the form but notices that it needs a correction so they resend the form to the initiator to correct and then the initiator corrects the same form and sends it back to the approver but when the approver receives the form the second time fields like, their decision, their comments from the first time should clear out. 

Currently when i added the code that you provided, the process stops running the very first time when the approver chooses the option to send the form back to the initiator for correction. Do you happen to know what may be causing this situation?

Thank you so much for helping. 

0 0
replied on November 20

I'm not certain what you mean by the form "stops running" - is the instance being suspended or something like that?

0 0
replied on November 20

Yes that is correct. It gets suspended. 

 

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

Sign in to reply to this post.