Home › Forums › Autocomplete › Auto Complete only if targeted fields are empty
- This topic has 17 replies, 2 voices, and was last updated 3 years, 7 months ago by Alexander Bautz.
-
AuthorPosts
-
-
April 15, 2021 at 01:09 #33210
I would like Auto Complete to only populate those fields that are empty when addressed in the setFields section. How could that be accomplished?
Thanks
MikeS -
April 15, 2021 at 16:19 #33221
I didn’t really have any way to control this in the code, but I have made a small adjustment to the code to let you use the parseFunction to check the current value – and if it is not empty it will set the current value and not the value pulled form the AC.
Try the attached version (you must rename it from .txt to .js and and replace the file you have in /SPJS/DFFS/plugins).
Use it like this:
// the setFields section of your AC function call: "setFields": [ { "fromFIN": ["Your_field_name"], "joinBy": "", "toFIN": "Target_field", "parseFunction": "customParseFn", "skipIfEmpty": true } ]
The parseFunction is added to your Custom JS:
function customParseFn(val, fin){ var currVal = getFieldValue(fin); var rVal = val; if (currVal.length > 0) { rVal = currVal; } return rVal; }
Let me know how this works out.
Alexander
Attachments:
-
April 15, 2021 at 22:47 #33226
Alexander,
I’ve tried this on New and Edit forms and it is not working as needed. If there are blank fields in the source list record the Template Type is not showing up in my Autocomplete Template selection field. Kind of opposite from what I need. In order to better communicate what is needed I’ve attached a diagram that should help.
Thanks
MikeSAttachments:
-
April 16, 2021 at 08:14 #33253
Please ensure that the previous version of the script is not cached in your browser by hovering over the “Enhanced with DFFS” link and check the version – it should be 1.6.52.
Alexander
-
April 19, 2021 at 17:26 #33266
Yes, version 1.5.52, April 15, 2021, is shown. It is not working properly as described in the diagram above that explains it in more detail.
Thanks for your help,
MikeS- This reply was modified 3 years, 7 months ago by MikeS.
-
April 19, 2021 at 18:44 #33269
Ah, I think the problem is “skipIfEmpty” in my code snippet – I didn’t realize it was set to true – try it like this:
"setFields": [ { "fromFIN": ["Your_field_name"], "joinBy": "", "toFIN": "Target_field", "parseFunction": "customParseFn", "skipIfEmpty": false } ]
Alexander
-
April 19, 2021 at 20:12 #33274
I changed skipIfEmpty to “false.” That allows me to see the complete list of Template Types in the Autocomplete list Template selection field (proper operation).
Unfortunately, all fields are still being overwritten in the Autocomplete list, whether blank or not.
MikeS
-
April 19, 2021 at 20:18 #33276
I seems to work in my test – try adding a debugger here to “see” what is being set:
function customParseFn(val, fin){ var currVal = getFieldValue(fin); var rVal = val; debugger; if (currVal.length > 0) { rVal = currVal; } return rVal; }
The debugger statement will pause the function and bring up the developer console – when it pauses, hover over the function arguments “val” and “fin” and the variables “currVal” and “rVal” to see the value.
The if(currVal.length > 0) line is supposed to identify that the current form has a value in the field and re-set the value to the one already in the field.
Let me know what the debug shows.
Alexander
-
-
April 19, 2021 at 20:54 #33281
Custom JS gives me a yellow ! triangle: “Forgotten ‘debugger’ Statement?” Nothing happens when Edit form opened (developer console is not opened).
MikeS
-
April 19, 2021 at 21:12 #33283
The triangle is as expected – the debugger statement is only used when debugging and must not be forgotten in a production environment.
The customParseFn function should be invoked every time you change the AC-field. If it does not you must ensure you have added it in the “parseFunction” parameter in your AC-setup.
Alexander
-
-
April 20, 2021 at 00:12 #33285
The ParseFn function is defined as follows in my CustomJS prior to AC statements:
function customParseFn(val, fin){ var currVal = getFieldValue(fin); var rVal = val; if (currVal.length > 0) { rVal = currVal; debugger; } return rVal; }
AC code and sample of SetFields:
spjs.ac.textField({ "applyTo": "TemplateType", "helpText": "", "loadText": "", "listGuid": "{redacted}", "listBaseUrl": "redacted", "showField": "Title", "searchFields": ["Title"], "filterCAML": "", "useREST": false, "preloadData":false, "filterREST": "", "optionDetailFields": [], "optionDetailPrefix": [], "enforceUniqueValues": false, "rowLimit": 30, "listOptionsOnFocus": true, "minLengthBeforeSearch": 1, "reValidateOnLoad": false, "allowAddNew": false, "isLookupInSelf": false, "addNewAdditionalFields": [], "multiselect": false, "multiselectSeparator": "; ", "orderBy": [ { "fin":"Title", "ascending":true } ], "clearSetFieldsOnInvalidSelection": true,
// the setFields section of your AC function call: "setFields": [ { "fromFIN":"Description", "joinBy": "", "toFIN":"Description", "parseFunction": "customParseFn", "skipIfEmpty": false },
Still not working. Running latest DFFS package.
MikeS
- This reply was modified 3 years, 7 months ago by MikeS.
-
April 20, 2021 at 09:53 #33289
Not sure what is wrong, but can you post the complete code you use in your spjs.ac.textField function call so I can try to figure out what is going on?
Replace any sensitive info with a dummy-value so the code structure is complete.
Alexander
-
April 20, 2021 at 16:43 #33291
This file is loaded before executing the Autocomplete Custom JS
_scripts/PullInformationFromConnectedList.js
Complete AC code:
spjs.ac.textField({ "applyTo": "TemplateType", "helpText": "", "loadText": "", "listGuid": "{redacted}", "listBaseUrl": "redacted", "showField": "Title", "searchFields": ["Title"], "filterCAML": "", "useREST": false, "preloadData":false, "filterREST": "", "optionDetailFields": [], "optionDetailPrefix": [], "enforceUniqueValues": false, "rowLimit": 30, "listOptionsOnFocus": true, "minLengthBeforeSearch": 1, "reValidateOnLoad": false, "allowAddNew": false, "isLookupInSelf": false, "addNewAdditionalFields": [], "multiselect": false, "multiselectSeparator": "; ", "orderBy": [ { "fin":"Title", "ascending":true } ], "clearSetFieldsOnInvalidSelection": true, // the setFields section of your AC function call: "setFields": [ { "fromFIN":"Fin1", "joinBy": "", "toFIN":"Fin1", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin2", "joinBy": "", "toFIN":"Fin2", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin3", "joinBy": "", "toFIN":"Fin3", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin4", "joinBy": "", "toFIN":"Fin4", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin5", "joinBy": "", "toFIN":"Fin5", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin6", "joinBy": "", "toFIN":"Fin6", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin7", "joinBy": "", "toFIN":"Fin7", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin8", "joinBy": "", "toFIN":"Fin8", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin9", "joinBy": "", "toFIN":"Fin9", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin10", "joinBy": "", "toFIN":"Fin10", "parseFunction": "customParseFn", "skipIfEmpty": false }, { "fromFIN":"Fin11", "joinBy": "", "toFIN":"Fin11", "parseFunction": "customParseFn", "skipIfEmpty": false }, ], "debug": false });
- This reply was modified 3 years, 7 months ago by MikeS.
-
April 21, 2021 at 15:45 #33294
Thanks,
If the debugger statement in the function does not actually bring up the developer tools to pause the code I’m wondering if you might have another function with the same name in your custom js? – if so, the last function added will be the one used.If you have a duplicate you must change one of the functions and update the name used in the parseFunction parameter in the AC function call.
Alexander
-
April 21, 2021 at 18:48 #33296
Nope, I’ve run the AC code above as the only Custom JS code and have placed it after other Custom JS with same results. The Template Type fields always overwrite the AC list fields whether the AC list fields are populated or not.
MikeS
-
April 22, 2021 at 19:51 #33303
This is very strange. I have tested a similar setup and cannot reproduce it. Could you send me some screenshots of your custom js, your form where you have the autocomplete and the list where you have the data to fill the autocomplete field and I’ll try to figure out what is going on.
Send it to the email you receive the forum notifications from.
Alexander
-
-
April 23, 2021 at 00:18 #33306
I will set up two demo lists and see if I can replicate the problem with new lists and go from there.
MikeS
-
April 23, 2021 at 15:23 #33311
OK, let me know how it works out.
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.