I can get values using data.field_XX for a detail view. and can get form values as well.
but i have a scene with a grid view on it… and i want to disable the submit button if the grid is empty.
if i use data.field_XX i keep getting ‘undefined’ and i cant figure out how to get the value of a grid item.
trying field_XX_raw didnt help, nor did data.field_XX[0]
View_100 is a grid and thats the challenge im having… trying to figure out how to get the data from that grid.
View_101 is a form and I have it worked out to not submit if 101 field58 or field54 are empty.
running into trouble with view 100 though. cant figure out the syntax to check if view_100 field_58 record[0] exist or empty.
Yes, there can be several line items in view_100. I only care that its not completely empty.
view100 starts empty for every new case. the workflow is that the team should hit the “add line item” button after entering data, which then saves the information from view101 into view100. once view100 has SOMETHING in it, then its safe to submit the form.
I have this to block the submit action and alert the user that they need to click the add button. this solves the view101 portion. when they click addlineitem it saves it to the view100 grid.
if ($('#view_101-field_58').val() != "") {
console.log($('#view_101-field_58').val())
console.log($('#view_100-field_58').val());
alert ("2 Please Click \"Add Line Item\" to save the last entry. Or reset the dropdowns to \"Select...\" before saving.")
return false
}
if ($('#view_101-field_54').val() != "") {
alert ("3 Please Click \"Add Line Item\" to save the last entry. Or reset the dropdowns to \"Select...\" before saving.");
console.log($('#view_101-field_54').val())
console.log($('#view_100-field_58').val())
return false;
}
// Check if field_58 in view_101 is not empty
if ($(‘#view_101-field_58’).val() !== “”) {
console.log("Field_58 View_101: " + $(‘#view_101-field_58’).val());
console.log("Field_58 View_100: " + $(‘#view_100-field_58’).val());
alert(“Please click "Add Line Item" to save the last entry, or reset the dropdowns to "Select…" before saving.”);
return false;
}
// Check if field_54 in view_101 is not empty
if ($(‘#view_101-field_54’).val() !== “”) {
alert(“Please click "Add Line Item" to save the last entry, or reset the dropdowns to "Select…" before saving.”);
console.log("Field_54 View_101: " + $(‘#view_101-field_54’).val());
console.log("Field_58 View_100: " + $(‘#view_100-field_58’).val());
return false;
}
here is the improved version
regards : wordcombine
A table that has no data has this class on the tr: kn-tr-nodata so the below code should work for what you need.
$(document).on('knack-view-render.view_101', function(event, view, data) {
$('#view_160 .kn-button').on('click', function() {
if ($('#view_101-field_58').val() != "") {
console.log($('#view_101-field_58').val());
console.log($('#view_100-field_58').val());
alert ("2 Please Click \"Add Line Item\" to save the last entry. Or reset the dropdowns to \"Select...\" before saving.");
return false;
}
if ($('#view_101-field_54').val() != "") {
alert ("3 Please Click \"Add Line Item\" to save the last entry. Or reset the dropdowns to \"Select...\" before saving.");
console.log($('#view_101-field_54').val());
console.log($('#view_100-field_58').val());
return false;
}
if ($('#view_100 tbody tr.kn-tr-nodata').length) {
alert('No data in table');
return false;
}
});
});
If this isn’t quite right please let us know and we will try again.
It worked! thanks! sorry for the delay I didnt have a chance to check it out until now. thank you so much for the help that will save a lot of aggravation