Take the 2-minute tour ×

In my trade order form, if the user selects order type = "limit" then a limit price must be specified. I am trying to enforce this rule using a funcCall, but it is not working. If limit order is selected and the limit price field is left blank, the validation engine validates the form successfully. Here's my HTML:

    <label for=tradeForm_orderType>Order Type</label>
    <select id=tradeForm_orderType name=orderParams.type>
        <option value=Market>Market</option>
        <option value=Limit>Limit</option>

<li id=tradeForm_limitPriceItem>
    <label for=tradeForm_limitPrice>Limit Price</label>
    <input class="validate[funcCall[checkLimitOrder],custom[number]]"
        type=text name=orderParams.limitPrice.amount id=tradeForm_limitPrice>

And here's my checkLimitOrder function:

function checkLimitOrder(field, rules, i, options) {
    if ($('#tradeForm_orderType').val() === 'Limit' && field.val().length === 0) {
        return 'Please enter a limit price';

This almost works! checkLimitOrder is indeed called and it returns the error message. However on return, the jQuery validation engine ignores the error message based on the following logic (lines 582-583):

// If the rules required is not added, an empty field is not validated
if(!required && field.val() == "") options.isError = false;

Well, I can't make the field required as it is only conditionally required. Is there any way I can work around this issue?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Answering my own question.

Turns out that the validation engine does not validate hidden fields (although this is not explicitly documented. So the solution was to hide limitPriceItem when the field was not required. Now I can put "validate[required,custom[number]]" on the limit price field and it validates only when the field is visible.

share|improve this answer

Your Answer


