Jump to content
Changes to the Jaspersoft community edition download ×

How to intercept submit event in custom jsp


mbarker62

Recommended Posts

I've created a custom jsp to change titles on an input control along with some validation.  The validation is being done outside the usual constructs of a numeric input control where the min and max value are set because the min changes based on some other input control.  It hasn't been easy but I've been able to workaround events that should have been available but aren't.  Until now.


Is there a way to intercept the submit event on a customized jsp?  I can't seem to locate a click event on the Apply button or the submit event on the form; those functions are below containing "console.log". If some fields are invalid, then I want to stop the submit. 


<%--Include templates--%>
<jsp:include page="InputControlTemplates.jsp" />

<%-- input controls container --%>
<ul class="list inputControls" id="inputControlsContainer"></ul>

<script type="text/javascript">

    jQuery(document).on("controls:initialized", function(event, controlsViewModel) {

        controlsViewModel.draw = function (jsonStructure) {

            var drawControl = function (container, jsonControl) {
                if (jsonControl.visible) {
                    var control = this.findControl({id:jsonControl.id});
                    container.append(control.getElem());
                }
            };

            _.each(jsonStructure, _.bind(drawControl, this, jQuery("#inputControlsContainer")));

            setDistanceTitle(nonFrontLoader.title);
            setDistanceValue(nonFrontLoader.default);
            setDistanceWarning("");

        };

        
    });

    jQuery("#inputControlsContainer").on("focusout", "#TruckId", function() {
        if (isFrontLoader()) {
            setDistanceTitle(frontLoader.title);
            setDistanceValue(frontLoader.default);
        } else {
            setDistanceTitle(nonFrontLoader.title);
            setDistanceValue(nonFrontLoader.default);
        }
        setDistanceWarning("");
    });

    jQuery(document).on("change", "#distance", function() {
        var inputDistance = getDistanceValue();
        var isFL = isFrontLoader();
        if (isFL && inputDistance < frontLoader.min) {
            var msg = warning + frontLoader.min;
            setDistanceWarning(msg);
        } else if (!isFL && inputDistance < nonFrontLoader.min) {
            var msg = warning + nonFrontLoader.min;
            setDistanceWarning(msg);
        } else {
            setDistanceWarning("");
        }

    });

    jQuery(document).on("click", "#apply", function() {
        console.log("apply click");
    });

    jQuery(document).on("submit", function() {
        console.log("submit form");
    });

    var frontLoader = {default:15, min:5, title:"Distance in meters (min:5)"};
    var nonFrontLoader = {default:500, min:50, title:"Distance in meters (min:50)"};
    var warning = "Distance cannot be less than ";

    function isFrontLoader() {
        var frontLoaderEl = jQuery("#isFL .sSelect-input span");
        var isFrontLoaderNum = parseInt(frontLoaderEl.html());
        return Boolean(isFrontLoaderNum);
    };

    function setDistanceWarning(msg) {
        jQuery("#distance label span.warning").html(msg);
    };

    function setDistanceTitle(title) {
        jQuery("#distance label span.wrap").html(title);
    };

    function setDistanceValue(value) {
        jQuery("#distance input").val(value); 
    };

    function getDistanceValue() {
        return jQuery("#distance input").val(); 
    };

</script>
 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...