Add a note to self textarea in a DFFS form

I got a request:

Hi Alexander,
I hope you are doing well. I’m wondering if you’ve done anything like this before: a field or area on an item where someone can add their own notes not visible to anyone except the logged in user. I thought maybe a rule but what if one person has their notes and someone else has their own? Thanks in advance for any advice on how you’d handle it.

This can be done with a few lines of Custom JS as shown below. This method stores the text in localStorage in the browser. Please note that this requires the localStorage to be activated (it is by default, but it can be turned off).

You must also add a field named _DFFSID to your form to hold the automatically generated unique itemID used to identify the values.

Add this to a table row added in your DFFS tab:

<textarea id="dffs_note_to_self" style="height:75px;width:100%;box-sizing:border-box;" onkeyup="saveToLocalStorage(this)"></textarea>

Then add this to your Custom JS:

function saveToLocalStorage(elm){
    var val = jQuery(elm).val();
    var id = getFieldValue("_DFFSID");
    localStorage.setItem(id,escape(val));
}

function dffs_ready(){
    var id = getFieldValue("_DFFSID");
    var noteToSelf = localStorage.getItem(id);
    if(noteToSelf !== null){
        jQuery("#dffs_note_to_self").val(unescape(noteToSelf));
    }
}

You can add this to NewForm, DispForm and EditForm and the text you enter will show every time you open it – like this:

The text is automatically saved when you type the value in the textarea, but because it uses the localStorage in the browser to store the text it is not saved in the list item and is only available if you open the item in the same browser on the same computer as you used to type the text in.

Let me know in the comments how this works out.

Best regards,
Alexander

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.