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

Question

Question

Possible to Toggle Signature Fields between read-only and required using JS?

asked two days ago

I've done this for other fields in the past, but not signature fields.  If possible I would like to toggle four different signature fields between read-only and required based on the BP step ID.  Has anyone else accomplished this?

Below is a snippet of my JS, but just can't get it to work correctly.  Wondering if the signature field is a certain attribute that you can't do this with?

Any insight would be greatly appreciated.

Thanks

//Setting Signature Fields Required or Read-Only based on process step

$(document).ready(function () {
    // Mapping of signature fields to their respective valid stage IDs
    const signatureFieldStages = {
        'signatureHR': ['12'], 
        'signatureFirst': ['1', '24', '28', '31'],
        'signatureSecond': ['25', '26'],
        'signatureCM': ['8']
    };

    setTimeout(function () {
        // Get the current stage value using the ID selector
        const currentStage = $('#Field160').val(); // Target the field by its ID
        console.log('Current Stage:', currentStage); // Debugging: Check if the correct value is being fetched

        // Iterate through each signature field
        for (const [fieldClass, validStages] of Object.entries(signatureFieldStages)) {
            console.log('Checking field:', fieldClass, 'Valid Stages:', validStages); // Debugging

            if (validStages.includes(currentStage)) {
                // If the current stage matches one of the valid stages for this field
                $(`.${fieldClass}`).prop('readonly', false).attr('required', 'required'); // Enable and make required
                console.log(`Field ${fieldClass} should be enabled and required`);
            } else {
                // Otherwise, make it readonly and not required
                $(`.${fieldClass}`).prop('readonly', true).removeAttr('required');
                console.log(`Field ${fieldClass} should be readonly and not required`);
            }
        }
    }, 500); // Adjust timeout if needed
});

 

0 0

Answer

APPROVED ANSWER
replied two days ago Show version history

Signature fields are tricky when it comes to being readonly. Once they have been signed in a process step they must be readonly when the form loads in order for it to be shown to any user later on in the process. In classic forms this means you will need to have a separate form for each step of the process and use readonly in the field's settings. You will not be able to replicate this with just JS in any version of Laserfiche.

In the new form designer with Laserfiche 12, you can enable the signature field to be readonly once it has been signed. What this means is you can use field rules to show the field based on the process step (new feature), and once it is signed keep it on the form so future approvers can see it. The saved form can then show all signatures/approvals. You can, but shouldn't, show all signature fields and trust the users to only sign what they need to and just use the readonly once signed setting. The nice part about this is you can keep using  a single form throughout the entire process and dont need to duplicate anything

5 0

Replies

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

Sign in to reply to this post.