I’m new to this, but I’m sure this will be easy for some of you veterans!
Scene with two views:
view 91 is a details view
view 88 is a form view
I want to have the form validate that a field from the details view is greater than a field from the form view on click - submit.
$(document).on(‘knack-view-render.view_88’, function(event, view, data) {
var LocationBoxes = $(‘Knack.models.view_91.attributes.field_101_raw’).val()
var RequestBoxes = $(’#view_88-field_108’).val()
$("#view_88 .kn-button").on(“click”, function() {
if (LocationBoxes < RequestBoxes) {
alert (“These are not the droids you are looking for.”);
return false;
}
})
});
Do I need to define the fields as variables or can I call them directly? Am I messing up the syntax somewhere?
$("#view_88 .kn-button").on(“click”, function() {
var LocationBoxes = Knack.models.view_91.attributes.field_101_raw;
var RequestBoxes = $(’#view_88-field_108’).val();
if (LocationBoxes < RequestBoxes) {
alert (“These are not the droids you are looking for.”);
return false;
}
})
});
Hi @Sunny_Singla - Thanks so much for the input. Per your suggestion, I changed the syntax in the variable line for the details field. Unfortunately, it’s still not executing the if statement as I’d hoped.
I’m wondering if the on click for the .kn-button is the best way to tag the event listener or if it should be something else as it’s a submit button type?
Sometimes in javascript, you need to convert $(’#view_88-field_108’).val() type of values to int using parseInt if you want to compare with integer value