Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
280
Regarding length validation in text editor
posted

Hello team,

I am facing one issue. So, my grid has 6-7 columns some r custom text/combobox and some are normal textbox. So I need to validate length. What is happening is validation is working but if minimum is 4 and if i type a and give 3 spaces it is not giving validation it's counting space?. How to fix it.

  • 660
    Offline posted

    Hello,

    Yes, I understand the issue you're facing. This behavior happens because spaces are being counted as characters during validation. To handle this correctly, you’ll need to implement custom validation for each column where this logic is necessary.

    Here's how you can achieve this:

    1/ Use editorOptions and set up validatorOptions inside each column’s configuration.

    2/ In validatorOptions, enable validation on all key events:

    onblur: true,
    onchange: true,
    onsubmit: true,

    3/ Then use the custom validator type, where you define a function that checks for non-space character length and shows a relevant error message.

    Here’s a sample of the custom validator function you can use:

    function (value) {
    
        const setMsg = txt => {
            $(this.element).igValidator("option", "errorMessage", txt);
            return false;
        };
        
        const trimmed = $.trim(value || "");
    
        if (trimmed.length < 4) {
            $(this.element).igValidator("option", "errorMessage", "Title must be at least 4 non-space characters.");
            return false;
        }
    
        return true;
    }

    This function ensures that inputs with only spaces (or fewer than 4 non-space characters) will not pass validation. You can adjust the logic per column as needed, depending on the specific requirements of that field.

    The described scenario could be observed here:

    To help you further, I’ve prepared a working sample you can refer to:

    Live Example on JSFiddle

    Please do not hesitate to contact me if you need any further assistance with this matter. 

    Regards,

    Georgi Anastasov

    Associate Software Developer

    Infragistics