jQWidgets Forums

jQuery UI Widgets Forums Plugins Validator, Drag & Drop, Sortable Not required but with rules….

This topic contains 2 replies, has 2 voices, and was last updated by  Andrew Cooper 10 years, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Not required but with rules…. #60708

    Andrew Cooper
    Participant

    I’ve got a form that has a text input field. The field isn’t required, so it can be blank. However, if it does have a value, then that value has to conform to certain rules. I have the current rule for the field defined…

    {input: "#edit_text", message: "Text must be from 4-15 characters.", action: "keyup", rule: "length=4,15"}

    I don’t have a “required” rule. However, when submitting the form it fails based on the the fact that the field has 0 characters. How do I set this up?

    Andrew

    Not required but with rules…. #60711

    Dimitar
    Participant

    Hello Andrew,

    Please try applying the following custom rule to your input:

    $('#testForm').jqxValidator({ rules: [
        { input: '#userInput', message: 'The username should be blank or between 4 and 15 characters long!', action: 'keyup, blur', rule: function (input, commit) {
            var value = input.val();
            if (value == "" || (value.length >= 4 && value.length <= 15)) {
                return true;
            } else {
                return false;
            }
        }
        }]
    });

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Not required but with rules…. #60716

    Andrew Cooper
    Participant

    That works perfectly. You are the man.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.