The existing sample code in the documentation doesn’t work (below) for setting the value of a blank field on the form render. I am wondering if anyone knows how this can be done now.
$(document).on('knack-view-render.view_52', function(event, view, data) {
// The connected record id value
var connectionId = "5b2ac7fc66b6036b8f859c45";
// Update the view and field ids for your application
$('#view_52-field_3').val(connectionId);
$('#view_52-field_3').trigger("liszt:updated");
});
Thank you for sharing! Please consider reaching out to our support team to report this sample code as not working for your app. They will be able to troubleshoot this for you and report the issue to our engineering team if it ends up being a platform issue.
If that’s the case then the issue is that the code is an example snippet it’s not to be copied and used.
There are 3 variables
View Id= view_xyz this can be found when you select the view in the builder then look at the URL and the view_… Is your viewId
Field Id= field_123 you can find this in the builder by going to data the select the object then just above the fields section is a toggle to turn field IDs on or off then find the field for the select.
Connection Id - this is a little trickier to get dynamically but you can usually find this in the app URL somewhere depending on what you are trying to do if the id you’re after is not there then you can use a view based API calls to get this.
If you want more help with this then please DM me and we can set up a meeting to discuss further.
This is not an easy thing to do it took us about a year to figure it out and now we use this quite a lot in our app.
i appreciate it. i understand how this code is supposed to work. i use javascript in my apps. the issue is that this method not working, which knack’s support has already confirmed for me and referred the issue to engineering because the sample code they use in the documentation no longer works. they also told me that they don’t support javascript issues, so referred me here in case people have had success using other methods.
We use this code all the time a lot in our app probably about 10 different forms in variations of this code. It does work so not sure why support would say that.
function addConnectionIdToRecord (viewId, conxFieldId, connectionId = null) {
const conxId = connectionId ? connectionId : getRecordID(); //Get Record Id from URL if no record Id passed in
const viewElement = $(`#${viewId}`).length ? $(`#${viewId}`) : $(`#connection-form-view:has(input[value="${viewId}"])`);
const assessConx = viewElement.find(`#kn-input-field_${conxFieldId}`);
assessConx.addClass(CLASS_HIDDEN);
assessConx.find('select').val(conxId).trigger('liszt:updated');
}
Both theses examples use the code in the example snippet from the dev wiki and are working fine in our app. The function addConnectionIdToRecord is used multiple times throughout our app.
i appreciate it. i just tested the method on a different account and it’s working there, so it appears to be an issue with my actual account or app. i’m just gonna make a copy of the problem app and see if that solves the problem.