Forum Replies Created
-
AuthorPosts
-
Not over to your other question. First you cannot rely on Chat GPT knowing how to write the correct code – It might be good for writing general code, but specific to the methods used in DFFS it just isn’t. There is no method in DFFS called spjs.dffs.getListItems or spjs.dffs.hideTab / showTab…
Here is the correct code using the methods available in DFFS:
function checkUserRoleAndToggleTab() { // Query the Roles list for current user let res = spjs.utility.queryItems({ listName: "Roles", query: "<Where><Eq><FieldRef Name='Person' LookupId='TRUE' /><Value Type='Integer'>" + _spPageContextInfo.userId + "</Value></Eq></Where>", viewFields: ["Role"] }); var hideTab = false; if (res.count > 0) { var role = res.items[0].Role; // Check if role is "Owner" if (role && role.trim().toLowerCase() === "owner") { hideTab = true; } } if (hideTab) { spjs.dffs.toggleVisibleTab("test", false); } else { spjs.dffs.toggleVisibleTab("test", true); } } // Run the function checkUserRoleAndToggleTab();
You can find more information about the CRUD methods in the classic version of DFFS here: https://spjsblog.com/forums/topic/query-update-delete-an-item-in-javascript/
Alexander
To your original question – here is how you can change it to work with dropdown fields:
const arrOfChoiceFields = ["Control_x0020_Certified_x003f_", "Checklist_x0020_Certified_x003f_", "Checker_x0020_Inventory_x0020_Ce"]; // Trigger on change arrOfChoiceFields.forEach(fin => { jQuery("#dffs_" + fin).find("select").on("change", function(){ toggleFieldToDisable(); }); }); function setFieldDisabled(fin, disabled){ if(disabled){ spjs.dffs.doReadOnly([fin]); }else{ spjs.dffs.undoReadOnly([fin]); } } function toggleFieldToDisable(){ let allYes = true; arrOfChoiceFields.forEach(fin => { if(getFieldValue(fin) !== "Yes"){ allYes = false; } }); setFieldDisabled("Requesting_x0020_an_x0020_Except",allYes); } // Trigger on page load toggleFieldToDisable();
Alexander
I need to know what you mean – is it a “Choice (menu to choose from) or a “Yes/No (check box) type field?
If it is the first, which subtype of field:
- Drop-Down Menu
- Radio Buttons
- Checkboxes (allow multiple selections)
Alexander
This example should work for radiobutton fields:
const arrOfChoiceFields = ["Control_x0020_Certified_x003f_", "Checklist_x0020_Certified_x003f_", "Checker_x0020_Inventory_x0020_Ce"]; // Trigger on change arrOfChoiceFields.forEach(fin => { jQuery("#dffs_" + fin).find("input:radio").on("click", function(){ toggleFieldToDisable(); }); }); function setFieldDisabled(fin, disabled){ if(disabled){ spjs.dffs.doReadOnly([fin]); }else{ spjs.dffs.undoReadOnly([fin]); } } function toggleFieldToDisable(){ let allYes = true; arrOfChoiceFields.forEach(fin => { if(getFieldValue(fin) !== "Yes"){ allYes = false; } }); setFieldDisabled("Requesting_x0020_an_x0020_Except",allYes); } // Trigger on page load toggleFieldToDisable();
Please verify that I have the correct internal names for your fields.
Alexander
What kind of choice field – radiobutton, dropdown or multiselect?
Alexander
I see. Chat GPT have not given you code that will work when you toggle the fields – only when the form loads (if you add the missing function).
What kind of fields are f1, f2 and f3 – Yes/No fields, or choice fields where one of the options are Yes?
Alexander
Where did you get the rest of the code from? – I’m guessing the code has been copied from somewhere, but you forgot to include this one function.
Without knowing exactly what you want to do with the rest of the code I’m not sure if just writing a code example will work for you, but from the function name I’m guessing it could be done something like this:
function setFieldDisabled(fin, disabled){ if(disabled){ spjs.dffs.doReadOnly([fin]); }else{ spjs.dffs.undoReadOnly([fin]); } }
Alexander
I replied to your question here: https://spjsblog.com/forums/topic/v4-4-5-55-has-been-released/#post-38556
Alexander
Hi,
This error states that you are missing a function named setFieldDisabled. If you have copied this custom js code from another site you must ensure you include this function also.Alexander
Hi,
I have confirmed a bug where “[[item:link_disp]]” and “[[item:link_edit]]” fails to pick up the ID of the item from NewForm and also fails to get the correct PageType. I’ll get it fixed and publish a new version tomorrow.You can construct the link manually like this – I think it should work in the current version also:
https://contoso.sharepoint.com/sites/your_site/_layouts/15/SPListForm.aspx?PageType=4&List=your_list_guid&ID=[[fieldValue:ID]]
Alexander
This should be fixed by adding min-width in the new version v1.1.5.0.
Alexander
I think I found what caused the bug, but cannot tell exactly why it suddenly started to fail after 15 years – it must be a browser issue I guess.
Let me know if the new version (DFFS v4.4.5.54 / vLookup v2.2.167) makes any difference.
Alexander
OK, one option is to manually add the Content Editor Web Parts that loads DFFS to the forms (NewForm, DispForm and EditForm). Just open the form and edit the page and insert a CEWP above and one below and refer a working list to copy the Content Link URL. Set both the webparts as Hidden.
This will “install” DFFS without using the DFFS Installer.
Alexander
Did you try my suggested solution (installing DFFS in the subsite and installing it from there)?
Alexander
Can you email me the external js-file (or at least an example of a function) so that I can see the relationship between the custom js function and the one loaded in the external file?
I tried going back to v1.0.50.0, but still could not get a function in Custom JS marked as async to load from a rule, or from a call from an external file.
Alexander
-
AuthorPosts